Defining sitemap nodes in code

Shad Storhaug edited this page Feb 9, 2014 · 1 revision

Want to contribute? See our Contributing to MvcSiteMapProvider guide.



Version 4.x Documentation


Unofficial Documentation and Resources

Other places around the web have some documentation that is helpful for getting started and finding answers that are not found here.

Tutorials and Demos

Version 4.x
Version 3.x

Forums and Q & A Sites

Other Blog Posts

Clone this wiki locally

In some cases, defining a sitemap node in code is more convenient than defining it in a sitemap xml file. To do this, decorate an action method with the MvcSiteMapNodeAttribute attribute. For example:

// GET: /Checkout/Complete 
[MvcSiteMapNodeAttribute(Title = "Checkout complete", ParentKey = "Checkout")] 
public ActionResult Complete(int id) 
{ 
    // ... 
}

Note that the ParentKey property should be specified to ensure the MvcSiteMapProvider can determine the hierarchy for all nodes. Only one node can exist without a ParentKey defined. This node will be used as the parent node for all others.