ASP.NET MVC 3 - 区域URL路由问题

pet*_*ete 3 asp.net-mvc

我有一个ASP.Net MVC 3应用程序.有2个区域:

  • Auth - 处理所有身份验证等
  • 管理 - 物业管理领域

在管理区域,我有一个ManagementController和一个PropertyController.ManagementController什么都不做,它只有一个简单的Index ActionResult而不是返回一个视图.

PropertyController有一个Index ActionResult,它返回一个包含属性列表的视图,以及一个以propertyId作为参数的Edit ActionResult.在属性索引视图中,我有一个包含属性列表的网格和一个使用以下代码编辑属性的选项:

@Html.ActionLink("Edit", "Edit","Property", new { id = item.PropertyId })
Run Code Online (Sandbox Code Playgroud)

理论上,这应该重定向到我的Property Controller的Edit ActionResult,但是它会重定向到ManagementController的Index ActionResult.我的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" });
Run Code Online (Sandbox Code Playgroud)

我的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
        );
Run Code Online (Sandbox Code Playgroud)

我错过了什么,为什么它会重定向到错误的控制器和动作?提前致谢!

MrG*_*igg 6

您可能需要在路由值参数中指定区域:

@Html.ActionLink("Edit", "Edit", "Property", new { id = item.PropertyID, area = "Management" }, new { })
Run Code Online (Sandbox Code Playgroud)

根据用于此调用的构造函数,您需要指定最后一个参数htmlAttributes,为了您的目的,该参数将为空.