Routing make me crazy thees days :( I have two areas: CityPage and Job On the city page I have a list of links that navigate to Job area. This is code for action and routing for CityPage:
public ActionResult Index(string city, string countryCode)
{
return View();
}
In CityPageAreaRegistration.cs class:
context.MapRoute(
null,
"CityPage/{countryCode}/{city}",
new { area = "CityPage", controller = "Home", action = "Index", city = "" }
);
URL that I get here is fine
http://localhost/CityPage/UK/London
From CityPage index I can navigate to Jobs list (Job/Home/Index
)
@Html.ActionLink("Jobs", "Index", "Home", new { area = "Job" }, null)
This is code from Job area:
public ActionResult Index()
{
return View();
}
context.MapRoute(
null,
"{area}/{countryCode}/{city}/Job/{controller}/{action}",
new { area = "Job", controller = "Home", action = "Index",
countryCode = "UK",
city = "London"
}
);
URL that I get here is still fine
http://localhost/CityPage/UK/London/Job
But on that page I have link to job details (Job/Home/Show
)
@Html.ActionLink("Job Example", "Show", "Home", new { area = "Job", jobId = 8765 }, null)
And URL that I get is
http://localhost/CityPage/UK/London/Job/Home/Show?jobId=8765
I have tried to add routing like this
context.MapRoute(
"Jobs",
"{area}/Job/{jobId}",
new
{
area = "Job",
controller = "Home",
action = "Index",
countryCode = "RS",
city = "Kragujevac",
jobId = ""
}
);
But it doesn't work. I don't know what am I doing wrong :( URL that I am trying to get is something like
http://localhost/CityPage/UK/London/Job/8765
I still learning about routing. But areas make me ...
I don't add any routing to Global.asax I think that I need to write routing code in areas routing.cs classes, am I right?