4

I'm trying to hide a node from my site menu, but display it in my breadcrumbs

I'm following the tutorial here: https://github.com/maartenba/MvcSiteMapProvider/wiki/Advanced-Node-Visibility

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

The above doesn't seem to work. It shows up both in my site menu, and breadcrumbs.

Null Reference
  • 11,260
  • 40
  • 107
  • 184
  • did you try to set `siteMapNodeVisibilityProvider="MvcSiteMapProvider.FilteredSiteMapNodeVisibilityProvider, MvcSiteMapProvider"` in web.config? It is working for me – angularrocks.com Apr 08 '13 at 12:31

3 Answers3

3

We created an OnlyBreadCrumbMVCSiteMapNodeAttribute. We decorate any code we want the attribute

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

Also have a visibilty provider

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

Use like

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

Upload Documents will be breadcrumb title. AssetDocuments is the Parent Key

If you pass the 3rd parameter, that sets a key of the breadcrumb node itself

GraemeMiller
  • 11,973
  • 8
  • 57
  • 111
  • Looks great! so you annotate your Actions with [OnlyBreadCrumbMvcSiteMapNodeAttribute]? Do you need to change anything else? – Null Reference Mar 07 '13 at 10:50
  • Great! You saved me a lot of research. – Kremena Lalova Dec 18 '14 at 16:09
  • Will this annotation disregard the default visibility provider (I have a custom one), or will it run on top of that (meaning either the custom provider or this one would say false for the visibility, the node wouldn't appear)? – Csaba Toth Jul 15 '16 at 02:05
3

You should use this guide on how to hide a node

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

Some settings you can set from the link above:

<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>

Once you have added the app settings, add the following to any node you want to see in the breadcrumbs but not the menu:

visibility="SiteMapPathHelper,!*" (SiteMapPathHelper - the node is visible in the sitemappath, !* - it is invisible for all other controls)

eg:

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

Other options available:

Type..........................What it Affects
CanonicalHelper.......The Canonical HTML Helper
MenuHelper..............The Menu HTML Helper
MetaRobotsHelper....The Meta Robots HTML Helper
SiteMapHelper..........The SiteMap HTML Helper
SiteMapPathHelper...The SiteMapPath HTML Helper
SiteMapTitleHelper...The Title HTML Helper
XmlSiteMapResult....The sitemaps XML output of the /sitemap.xml endpoint

garethb
  • 3,951
  • 6
  • 32
  • 52
0

add this to your web.config

<appSettings>
  <add key="MvcSiteMapProvider_DefaultSiteMapNodeVisibiltyProvider" value="MvcSiteMapProvider.FilteredSiteMapNodeVisibilityProvider, MvcSiteMapProvider"/>
<appSettings>
Willy
  • 1,689
  • 7
  • 36
  • 79