我正在使用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,这是正确的。
用户管理网址应为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" }
);
请问,我该如何解决这个问题?
感谢。
答案 0 :(得分:0)
感谢NightOwl888。
问题出在我的助手班上。
[EditorBrowsable(EditorBrowsableState.Never)]
public string ToHtmlString() {
string output = "";
TagBuilder tagBuilder = null;
if (!string.IsNullOrEmpty(this._icon)) {
tagBuilder = new TagBuilder("i");
tagBuilder.AddCssClass(string.Concat("menu-icon ", this._icon.Replace("/", "")));
output = string.Concat(output, tagBuilder.ToString());
}
tagBuilder = new TagBuilder("span");
tagBuilder.AddCssClass("menu-text");
tagBuilder.InnerHtml = this._text;
output = string.Concat(output, tagBuilder.ToString());
if (this._isDeropDown) {
tagBuilder = new TagBuilder("i");
tagBuilder.AddCssClass("menu-expand");
output = string.Concat(output, tagBuilder.ToString());
}
tagBuilder = new TagBuilder("a");
if (this._isDeropDown) {
tagBuilder.AddCssClass("menu-dropdown");
}
UrlHelper urlHelper = new UrlHelper(this._html.ViewContext.RequestContext);
tagBuilder.MergeAttribute("href", urlHelper.Action(this._actionName, this._controllerName, new { area = this._areaName }));
tagBuilder.InnerHtml = output;
return MvcHtmlString.Create(tagBuilder.ToString()).ToString();
}
更改:
tagBuilder.MergeAttribute("href", string.Concat(this._areaName, urlHelper.Action(this._actionName, this._controllerName)));
要:
tagBuilder.MergeAttribute("href", urlHelper.Action(this._actionName, this._controllerName, new { area = this._areaName }));