【发布时间】:2012-02-11 12:19:36
【问题描述】:
如果我们在一个项目中有多个区域,路由值应该存储在哪里。
什么应该去Global.asax,什么在课堂上AreaAreaRegistration.cs
我不经常使用 asp mvc(这仍然是我的爱好),但路由总是让我遇到问题 :(
我必须举一个让我困惑的例子:
我有两个区域和一个区域中的链接 (CityPage) 应该在另一个区域中打开页面。
所以在我的global.asax 我有:
routes.MapRoute(
"CityPage_home",
"{country}/{city}",
new { controller = "Home", action = "Index", country = UrlParameter.Optional, city = UrlParameter.Optional }
);
routes.MapRoute(
"Default", // Route name
"{controller}/{action}/{id}", // URL with parameters
new { area = "CityPage", controller = "Home", action = "Index", id = UrlParameter.Optional } // Parameter defaults
);
这很有效。但是,如果我将“*CityPage_home*”从global.asax 移动到CityPageAreaRegistration.cs,那么当我单击应该在另一个区域打开页面的链接时,我的应用程序会崩溃,因为代码首先在CityPage/Home/Index 方法中输入。
我不明白为什么这种路由在第一种情况下有效,而在另一种情况下无效。有什么想法吗?
【问题讨论】:
标签: asp.net-mvc asp.net-mvc-3 asp.net-mvc-routing