MvcSiteMapProvider:URL不与工作区 [英] MvcSiteMapProvider: url not working with Area
本文介绍了MvcSiteMapProvider:URL不与工作区的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我使用MvcSiteMapProvider 4.6.18.0。
I'm using 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://本地主机/首页/指数这是正确的。
Dashboard url is http://localhost/Home/Index which is correct.
用户管理网址应该是的http://本地主机/管理/用户/指数而是它解析为的http://本地主机/首页/管理/用户/指数
Users Management url should be http://localhost/Admin/Users/Index but instead it is resolved as http://localhost/Home/Admin/Users/Index
它不应该有家庭在URL中。
it should not have Home in the url.
我已经经历了这么和其他论坛搜索,我无法找到一个解决方案。
I have search through SO and other forums, I couldn't find a solution.
区路线:
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" }
);
请,我该如何解决这个问题?
Please, how do I fix this?
感谢。
推荐答案
感谢NightOwl888。
Thanks to 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 }));
这篇关于MvcSiteMapProvider:URL不与工作区的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文