asp.net-mvc之ASP.NET MVC 3之区域 URL 路由问题
我有一个 ASP.Net MVC 3 应用程序。有 2 个区域:
- Auth - 处理所有的身份验证等
- 管理 - 属性(property)管理领域
在管理区域中,我有一个 ManagementController 和一个 PropertyController。 ManagementController 什么都不做,它只有一个简单的 Index ActionResult 而不是返回一个 View 。
PropertyController 有一个 Index ActionResult,它返回一个包含属性列表的 View ,以及一个 Edit ActionResult,它以 propertyId 作为参数。在属性索引 View 中,我有一个带有属性列表的网格和一个使用以下代码编辑属性的选项:
@Html.ActionLink("Edit", "Edit","Property", new { id = item.PropertyId })
理论上这应该重定向到我的属性 Controller 的编辑操作结果,但是它重定向到我的管理 Controller 的索引操作结果。我的 ManagementAreaRegistration 文件如下所示:
context.MapRoute(null, "management", new { controller = "management", action = "Index" });
context.MapRoute(null, "management/properties", new { controller = "Property", action = "Index" });
context.MapRoute(null, "management/properties/Edit/{propertyId}", new { controller = "Property", action = "Edit" });
我的 global.asax 的 RegisterRoutes 是这样的:
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
);
我错过了什么,为什么它会重定向到错误的 Controller 和操作? 提前致谢!
请您参考如下方法:
您可能需要在路由值参数中指定区域:
@Html.ActionLink("Edit", "Edit", "Property", new { id = item.PropertyID, area = "Management" }, new { })
根据用于此调用的构造函数,您需要指定最后一个参数 htmlAttributes,根据您的目的,该参数将为空。
1.本站遵循行业规范,任何转载的稿件都会明确标注作者和来源;2.本站的原创文章,请转载时务必注明文章作者和来源,不尊重原创的行为我们将追究责任;3.作者投稿可能会经我们编辑修改或补充。