【发布时间】:2013-01-19 13:05:57
【问题描述】:
对于 ASP.NET MVC 应用程序,我有 2 个控制器,名称为 Home。其中一个控制器在Areas 部分,一个不在。如果有人转到基本路径/,我试图默认使用Areas 部分中的控制器。我的印象是这是可能的。我有以下设置,我认为应该可以做到这一点 -
当我转到/ 时,我仍然被带到MVCArea01/Controllers/ 中的控制器,而不是MVCArea01/Areas/Admin/Controllers/。
(如果图片中的代码太小看不清,这里是方法的代码,RegisterRoutes)
public static void RegisterRoutes(RouteCollection routes)
{
routes.IgnoreRoute("{resource}.axd/{*pathInfo}");
routes.MapRoute(
"Default", // Route name
"{controller}/{action}/{id}", // URL with parameters
new { controller = "Home", action = "Index", id = UrlParameter.Optional }, // Parameter defaults
new[] {"MVCAreas01.Areas.Admin.Controllers"} // I believe this code should cause "/" to go to the Areas section by default
);
}
什么是正确的解决方案?
【问题讨论】:
标签: c# asp.net asp.net-mvc asp.net-mvc-routing asp.net-mvc-areas