编程语言
首页 > 编程语言> > c# – MVC SiteMap从menuhelper中隐藏节点,但在sitepathhelper中显示(breadcrumbs)

c# – MVC SiteMap从menuhelper中隐藏节点,但在sitepathhelper中显示(breadcrumbs)

作者:互联网

我正在尝试从我的站点菜单中隐藏节点,但是在我的面包屑中显示它

我在这里按照教程:https://github.com/maartenba/MvcSiteMapProvider/wiki/Advanced-Node-Visibility

<mvcSiteMapNode title="Create Customer" controller="Customer" action="Create" area="Home" clickable="false" visibility="SiteMapPathHelper,!*"/>  

以上似乎不起作用.它显示在我的网站菜单和面包屑中.

解决方法:

我们创建了一个OnlyBreadCrumbMVCSiteMapNodeAttribute.我们装饰我们想要属性的任何代码

public class OnlyBreadCrumbMvcSiteMapNodeAttribute : MvcSiteMapNodeAttribute
{
    public OnlyBreadCrumbMvcSiteMapNodeAttribute(string title, string parentKey)
    {
        Title = title;
        ParentKey = parentKey;
        VisibilityProvider = typeof(BreadCrumbOnlyVisibilityProvider).AssemblyQualifiedName;
    }
    public OnlyBreadCrumbMvcSiteMapNodeAttribute(string title, string parentKey, string key)
    {
        Title = title;
        Key = key;
        ParentKey = parentKey;
        VisibilityProvider = typeof(BreadCrumbOnlyVisibilityProvider).AssemblyQualifiedName;
    }
}

还有一个可见的提供者

public class BreadCrumbOnlyVisibilityProvider : ISiteMapNodeVisibilityProvider
{
    public bool IsVisible(SiteMapNode node, HttpContext context, IDictionary<string, object> sourceMetadata)
    {
        if (sourceMetadata["HtmlHelper"] == null || (string)sourceMetadata["HtmlHelper"] == "MvcSiteMapProvider.Web.Html.SiteMapPathHelper")
        {
            return true;
        }
        return false;
    }
}

用得像

06002

上传文件将是面包屑标题. AssetDocuments是父键

如果传递第3个参数,则设置面包屑节点本身的键

标签:c,asp-net-mvc,breadcrumbs,mvcsitemap,sitemapprovider
来源: https://codeday.me/bug/20190529/1179365.html