【发布时间】:2011-09-02 04:47:53
【问题描述】:
我正在使用 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 应用程序/区域时,我的路线都是默认的。即
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 Is it required to have "area" routevalue on actionlink if the application was grouped into areas?
【问题讨论】:
-
这是设计使然吗?也许您必须明确指定 Areas=""?
标签: asp.net-mvc-3 routes areas