Is there a simple method to extract additional properties from an mvcSiteMapNode?

Feb 8, 2011 at 1:01 PM

Just saw I want to add an additional property to my node in my sitemap - say something called "cssClass", so my node looks like this:

 

 <mvcSiteMapNode title="Home" controller="Home" action="Index" cssClass="home current"

 

Is there a way that I can easily pull out the "cssClass" property? Or is the only solution to write a provider?

Thanks

Feb 9, 2011 at 11:06 AM

Hi, yeah all you have to do is say:

SiteMap.CurrentNode["CssClass"]) 



I found this also added the cssclass to the link so you also need to change the following line in your web.config file:

<add name="MvcSiteMapProvider" type="MvcSiteMapProvider.DefaultSiteMapProvider, MvcSiteMapProvider" siteMapFile="~/Web.Sitemap" securityTrimmingEnabled="false" attributesToIgnore="cssClass;pageTitle" />

Hope this helps.

Feb 9, 2011 at 11:18 AM

Hi,

Thanks very much for your reply. I've come across your approach before - but it only appears to work with the CurrentNode.

So if I'm looping though a collection of nodes to say, build up my navigation links and I have a node model bound to a view, I cannot seem to get at additional properties.

The code out there that I've seen doing it involves using a custom provider.

On another note, the "imageUrl" property isn't available either

Coordinator
Feb 14, 2011 at 9:15 AM

Are you looping nodes in view(templates) or in controller code?

Feb 14, 2011 at 9:41 AM
Edited Feb 14, 2011 at 9:41 AM

I'm looping the nodes in view (templates)

 

I've cheated for now and put the values I need into the "Description" field. A little naughty so if anyone's got any alternatives I would love to hear them

Coordinator
Feb 14, 2011 at 11:07 AM

Not sure if I implemented those. Will check & fix.

Coordinator
Feb 17, 2011 at 12:05 PM
MetaAttributes property should contain your additional data