MVC SiteMap Hiding a node from menuhelper, but display in sitepathhelper (breadcrumbs)
Asked Answered
R

3

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.

Resting answered 3/3, 2013 at 13:45 Comment(1)
did you try to set siteMapNodeVisibilityProvider="MvcSiteMapProvider.FilteredSiteMapNodeVisibilityProvider, MvcSiteMapProvider" in web.config? It is working for meImpotent
D
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

Duroc answered 7/3, 2013 at 10:39 Comment(3)
Looks great! so you annotate your Actions with [OnlyBreadCrumbMvcSiteMapNodeAttribute]? Do you need to change anything else?Resting
Great! You saved me a lot of research.Evaporimeter
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)?Unfold
A
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

Aesthetics answered 23/11, 2014 at 23:31 Comment(0)
B
0

add this to your web.config

<appSettings>
  <add key="MvcSiteMapProvider_DefaultSiteMapNodeVisibiltyProvider" value="MvcSiteMapProvider.FilteredSiteMapNodeVisibilityProvider, MvcSiteMapProvider"/>
<appSettings>
Bouillon answered 24/4, 2014 at 11:33 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.