views:

119

answers:

1

I'm using v2.0 of the MVC SiteMap project.

With the System.Web.XmlSiteMapProvider in webforms, I often stored custom attributes on nodes, and accessed them through the Attributes[] collection. This is very useful for building non-standard collections of nodes, that all share an attribute.

The MVC SiteMap doesn't seem to support custom attributes. Is this right? If not, can anyone suggest a good way of identifying the nodes in my SiteMap that should be considered the "primary" navigation?


Edit:

I should clarify how attributes appear to "not work". When I add a custom attribute, e.g isPrimary="true" to my root node, my SiteMap.CurrentNode property is always null. However, the SiteMap.RootNode property is populated fine. Any ideas?


Further Edit:

Given that any additional attributes I add will added to RouteData, is there a way of adding an attribute to a node that isn't related in any way to the route? I'm thinking of an arbitrary parameter that I can use to identify certain nodes.

+2  A: 

This works just fine in the latest version of the provider. Just tested this using the latest source code and MVC Music Site Demo.

Pretty sure this always worked. The AddNode() methods all call the base.AddNode methods which will add whatever attributes you'd like.

Update:

Tried your example, works fine. When I tested this I actually debugged on the SiteMap.Provider.CurrentNode and the custom attributes were there. Maybe its a bug, try the latest drop?

jfar
Thanks for the feedback jfar. I have clarified my question, as my issue seems to be a little more subtle.
Paul Suart
OK thanks - I'll get the latest version.
Paul Suart
Ah-ha I think I see how it works now - any custom attributes are transformed into route values, right? I think the attribute I'm adding doesn't have a corresponding "slot" in the route. Thanks for your help.
Paul Suart