-
Notifications
You must be signed in to change notification settings - Fork 0
Action Filter Attributes
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 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 blog; }
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) { // ... }