【发布时间】:2012-01-10 20:38:06
【问题描述】:
路由让我在这几天发疯 :( 我有两个区域:CityPage 和 Job 在城市页面上,我有一个导航到工作区域的链接列表。 这是 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 = "" }
);
我在这里得到的网址很好
我可以从 CityPage 索引导航到工作列表 (Job/Home/Index)
@Html.ActionLink("Jobs", "Index", "Home", new { area = "Job" }, null)
这是来自工作区的代码:
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 还是可以的
但在那个页面上,我有指向工作详细信息的链接 (Job/Home/Show)
@Html.ActionLink("Job Example", "Show", "Home", new { area = "Job", jobId = 8765 }, null)
我得到的网址是
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 = ""
}
);
但它不起作用。我不知道我在做什么错:( 我想要获取的 URL 类似于
我还在学习路由。但是领域让我...
我没有向 Global.asax 添加任何路由我认为我需要在区域 routing.cs 类中编写路由代码,对吗?
【问题讨论】:
标签: asp.net-mvc asp.net-mvc-3 asp.net-mvc-routing asp.net-mvc-areas