【发布时间】:2015-07-27 20:21:49
【问题描述】:
我正在使用 MvcSiteMapProvider 4.6.18.0。
我能够生成菜单。
<mvcSiteMapNode title="Dashboard" controller="Home" action="Index" area="" imageUrl="glyphicon glyphicon-home" description="Colony dashboard">
<mvcSiteMapNode title="Profile" controller="Profile" action="Index" imageUrl="glyphicon glyphicon-user" description="My Profile" />
<mvcSiteMapNode title="Administration" imageUrl="fa fa-lock" description="" clickable="false" controller="" area="" url="2" key="administration">
<mvcSiteMapNode title="Users Management" controller="Users" action="Index" area="Admin">
<mvcSiteMapNode title="Add New User" controller="Users" action="Create" visibility="SiteMapPathHelper,!*" />
<mvcSiteMapNode title="Details" controller="Users" action="Details" visibility="SiteMapPathHelper,!*" preservedRouteParameters="id" >
<mvcSiteMapNode title="Edit" controller="Users" action="Edit" visibility="SiteMapPathHelper,!*" key="Users_Edit" preservedRouteParameters="id" />
<mvcSiteMapNode title="Delete" controller="Users" action="Delete" visibility="SiteMapPathHelper,!*" preservedRouteParameters="id" />
</mvcSiteMapNode>
</mvcSiteMapNode>
</mvcSiteMapNode>
仪表板网址是http://localhost/Home/Index,这是正确的。
用户管理 url 应该是 http://localhost/Admin/Users/Index 但它被解析为 http://localhost/Home/Admin/Users/Index
网址中不应有 Home。
我搜索了 SO 和其他论坛,但找不到解决方案。
区域路线:
public override void RegisterArea(AreaRegistrationContext context) {
context.MapRoute(
"Admin_default",
"Admin/{controller}/{action}/{id}",
new { controller = "Users", action = "Index", id = UrlParameter.Optional },
new string[] { "Project.Areas.Admin.Controllers" }
);
}
默认路线:
routes.MapRoute(
name: "Default",
url: "{controller}/{action}/{id}",
defaults: new { controller = "Account", action = "Initialize", id = UrlParameter.Optional },
namespaces: new string[] { "Project.Controllers" }
);
请问,我该如何解决这个问题?
谢谢。
【问题讨论】:
-
这里没有足够的代码来确定问题所在,因为您没有显示对
node.Url属性的调用,也没有发布您的路线。但是,您应该知道MvcSiteMapProvider使用.NET 路由来生成node.Url输出,因此如果您的路由配置不正确,您的URL 将不正确。请参阅文档的this section 以解决 MVC 中的 URL 生成问题。 -
BTW - ImageUrl 是一个特殊的字段,可以将值解析为 URL,您不应该在其中放置 CSS 类。为此目的使用custom attributes。
-
您发布的路线无法解释问题。 1)
AreaRegistration.RegisterAllAreas()是在RouteConfig.RegisterRoutes(RouteTable.Routes)之前被调用的吗? 2) 您的应用程序中是否还有其他未发布的路由或 RouteAttributes? 3)视图中的@Html.ActionLink("Users Management", "Index", "Users", new { area = "Admin" })是否正确解析URL? -
谢谢 NightOwl,问题是第 3 个问题。我正在将该区域传递给 url.action()。
标签: asp.net-mvc asp.net-mvc-5 mvcsitemapprovider