-->

MVC网站地图隐藏从menuhelper在sitepathhelper的节点,但显示器(面包屑)(M

2019-08-17 06:44发布

我试图隐藏我的网站菜单中的一个节点,但在我的面包屑显示它

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

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

上面似乎并没有工作。 它显示了无论是在我的网站的菜单,和面包屑。

Answer 1:

我们创建了一个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;
    }
}

使用像

  [OnlyBreadCrumbMvcSiteMapNode("Upload Documents", "AssetDocuments")] public virtual ActionResult FileUpload(int assetId) 

上传的文件将面包屑称号。 AssetDocuments是父项

如果你通过了第三个参数,即设置面包屑节点本身的关键



Answer 2:

您应该使用如何隐藏节点本指南

https://github.com/maartenba/MvcSiteMapProvider/wiki/Advanced-Node-Visibility-with-ISiteMapNodeVisibilityProvider

你可以从上面的链接设置一些设置:

<appSettings>
    <!-- Visibility will not filter to children -->
    <add key="MvcSiteMapProvider_VisibilityAffectsDescendants" value="false"/>
    <!-- Set default visibility provider -->
    <add key="MvcSiteMapProvider_DefaultSiteMapNodeVisibiltyProvider" value="MvcSiteMapProvider.FilteredSiteMapNodeVisibilityProvider, MvcSiteMapProvider"/>
</appSettings>

一旦你已经添加的应用程序设置,添加以下要在面包屑看到任何节点,但没有菜单:

visibility="SiteMapPathHelper,!*" (SiteMapPathHelper -节点是在可见的SiteMapPath,* -它是无形的所有其他控件)

例如:

<mvcSiteMapNode title="Administration" area="Admin" clickable="false" visibility="SiteMapPathHelper,!*" />

其它选项:

键入 它影响 .......................... 什么
CanonicalHelper .......该规范HTML助手
MenuHelper ..............菜单HTML助手
MetaRobotsHelper ....元机器人HTML助手
SiteMapHelper ..........网站地图HTML助手
SiteMapPathHelper ...的HTML的SiteMapPath助手
SiteMapTitleHelper ...标题HTML助手
XmlSiteMapResult ....在/sitemap.xml端点的站点地图XML输出



Answer 3:

添加到您的web.config

<appSettings>
  <add key="MvcSiteMapProvider_DefaultSiteMapNodeVisibiltyProvider" value="MvcSiteMapProvider.FilteredSiteMapNodeVisibilityProvider, MvcSiteMapProvider"/>
<appSettings>


文章来源: MVC SiteMap Hiding a node from menuhelper, but display in sitepathhelper (breadcrumbs)