Skip to content

Action Filter Attributes

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

SiteMapTitle

In some situations, you may want to dynamically change the SiteMap.CurrentNode.Title in an action method. This can be done manually by setting SiteMap.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(blogIdId); 
   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(blogIdId); 
   return View(blog); 
}

## SiteMapPreserveRouteData

When creating breadcrumb trails and not using Dynamic sitemaps, chances are route data on the breadcrumb links seems to be "lost". By applying the SiteMapPreserveRouteDataAttribute on an action method, route data of the requested action method is copied into the breadcrumb trail's route data.

[SiteMapPreserveRouteData] 
public ViewResult Show(int blogId) { 
   // ...
}

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