Question

I am using the latest Nuget package of MVC SiteMap provider. We are making heavy use of code based attributes defining nodes in our site.

E.g. [MvcSiteMapNode(Title = "Examination Types", ParentKey = "LookupTable", Key = "ExaminationTypeIndex")]

We want to make use of a custom visibility provider to hide nodes from SiteMap as per here

However we can't seem to specify node visibility attribute using Code based nodes? Is there anyway to do that. We can only specify a custom visibility provider and we would rather use the visible attribute.

Was it helpful?

Solution

Visibility is a custom attribute, so you need to supply it in the Attributes field in order to use it in conjunction with [MvcSiteMapNodeAttribute]. The only tricky part is that .NET attributes don't support dictionary types, so you need to supply the attributes as an escaped JSON string.

[MvcSiteMapNode(Title = "Examination Types", ParentKey = "LookupTable", Key = "ExaminationTypeIndex", Attributes = @"{ ""visibility"": ""SiteMapPathHelper,!*"" }")]

NOTE: If you need to supply multiple custom attributes, separate them with a comma.

Attributes = @"{ ""visibility"": ""SiteMapPathHelper,!*"", ""myCustomAttribute"": true }"

OTHER TIPS

The only way I found to do this is to create several custom visibility providers. For example, if your visibility flag could be 'true' and 'false'....then you would simply make a visiblity provider that always returned false. In the sitemapnodes you create in code - specify that provider.

If you do not want to do that on every attribute, make a new class that inherits from MvcSiteMapNodeAttribute that sets the proper visibility provider - then use that where appropriate.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top