MVC SiteMap Hiding the node from the helper menu, but displaying in the sitepathhelper (breadcrumbs)

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

I follow 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 does not work. It is displayed both in the menu of my site and in breadcrumbs.

+4
c # asp.net-mvc breadcrumbs mvcsitemap sitemapprovider
source share
3 answers

We created the attribute OnlyBreadCrumbMVCSiteMapNodeAttribute. We decorate any code that we need an 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; } } 

There is also 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 as

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

Downloading documents will be the title. AssetDocuments is the parent key

If you pass the third parameter, which sets the key for the node bundle itself

+3
source share

You should use this guide on how to hide the node.

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

Some settings that 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> 

After adding the application settings, add the following to any node that you want to see in breadcrumbs, but not in the menu:

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

eg:

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

Other options available:

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

+3
source share

add this to your web.config

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

All Articles