Skip to content

Using Action Filter Attributes

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

SiteMapTitle

In some situations, you may want to dynamically change the SiteMaps.Current.CurrentNode.Title in an action method. This can be done manually by setting SiteMaps.Current.CurrentNode.Title, or by adding the SiteMapTitle action filter attribute.

Imagine you are building a blog and want to use the Blog's Headline property as the site map node title. You can use the following snippet:

[SiteMapTitle("Headline")] 
public ViewResult Show(int blogId) { 
   var blog = _repository.Find(blogId); 
   return View(blog); 
}

You can also use a non-strong typed ViewData value as the site map node title:
[SiteMapTitle("SomeKey")] 
public ViewResult Show(int blogId) { 
   ViewData["SomeKey"] = "This will be the title";

   var blog = _repository.Find(blogId); 
   return View(blog); 
}

There is also a Target property that allows you to set the title of the parent of the current node.
[SiteMapTitle("Headline")]
[SiteMapTitle("Category", Target = AttributeTarget.ParentNode)]
public ViewResult Show(int blogId) { 
   var blog = _repository.Find(blogId);

   // Headline and Category are string properties of 
   // the blog model object.
   return View(blog); 
}

Want to contribute? See our Contributing to MvcSiteMapProvider guide.



Version 3.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