MvcSiteMapProvider:url 不使用 Area

MvcSiteMapProvider: url not working with Area

我正在使用 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>

仪表板 url 是 http://localhost/Home/Index,这是正确的。

用户管理 url 应该是 http://localhost/Admin/Users/Index but instead it is resolved as http://localhost/Home/Admin/Users/Index

url 中不应该有首页。

我已经在 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" }
        );

请问,我该如何解决这个问题?

谢谢。

感谢 NightOwl888。

问题出在我的助手 class。

[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 }));