我正在使用 MVC3 并在我的应用程序中有区域。一般来说,一切正常,我可以像这样导航到我的区域(例如 Admin=Area,Controller=Department):
<%: Html.ActionLink("Departments", "DepartmentIndex", "Department", new { area = "Admin"}, null )%>
但是,我注意到的是,如果我没有在 ActionLink 中指定区域,例如
<%: Html.ActionLink("Test", "Index", "Home")%>
如果我导航到“管理”区域,这将停止工作。即我的网址现在是 http://localhost/myproj/Admin/Home/Index 而不是 http://localhost/myproj/Home/Index
关于这里发生了什么的任何想法?
创建 MVC 应用程序/区域时,我的路线都是默认的。IE
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 },
new[] { "MyProj.Controllers" }
);
}
还有我的地区注册
public override void RegisterArea(AreaRegistrationContext context)
{
context.MapRoute(
"Admin_default",
"Admin/{controller}/{action}/{id}",
new { action = "Index", id = UrlParameter.Optional }
);
}
这是设计使然吗?这篇文章建议使用 RouteLink 而不是 ActionLink:说要使用 RouteLink 如果应用程序被分组到区域中,是否需要在 actionlink 上具有“区域”路由值?