-
Notifications
You must be signed in to change notification settings - Fork 218
Using Action Filter Attributes
Shad Storhaug edited this page Feb 10, 2014
·
1 revision
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.
- Upgrading from v3 to v4
- Routing Basics
- Configuring MvcSiteMapProvider
- Defining Sitemap Nodes in XML
- Defining Sitemap Nodes using .NET Attributes
- Defining Sitemap Nodes using IDynamicNodeProvider
- HtmlHelper Extensions
- Controlling URL Behavior
- Using Action Filter Attributes
- Sitemaps XML Protocol Endpoint for Search Engines
- Using Custom Attributes on a Node
- Specifying Node Order
- Advanced Node Visibility
- Multiple Navigation Paths to a Single Page
- Multiple Sitemaps in One Application
- Security Trimming
Other places around the web have some documentation that is helpful for getting started and finding answers that are not found here.
- MvcSiteMapProvider 4.0 - A Test Drive
- MvcSiteMapProvider 4.0 - SEO Features Tutorial
- How to Make MvcSiteMapProvider Remember a User’s Position
- MvcSiteMapProvider 4.0 - Cache Configuration
- MvcSiteMapProvider 4.0 - Extending the Cache
- MvcSiteMapProvider 4.0 - Unit Testing with the SiteMaps Static Methods
- Debugging an MvcSiteMapProvider Configuration
- Converting from C# to Vb MvcSiteMapProvider
- ASP.NET MVC Menu using Site Map Provider & Bootstrap 3 Navbar
- ASP.NET MVC SiteMapPath using Site Map Provider & Bootstrap Breadcrumbs
- NightOwl888's MvcSiteMapProvider Demos - Filter for "MvcSiteMapProvider" to see the most relevant.
- MvcSiteMapProvider Tutorial and Examples
- MvcSiteMapProvider Tutorial 2 - Breadcrumbs
- Getting Started with MvcSiteMapProvider
- Inside the MvcSiteMapProvider - Part 1
- Inside the MvcSiteMapProvider - Part 2: Dynamic node providers
- Inside the MvcSiteMapProvider - Part 3: The ISiteMapVisibilityProvider
- Inside the MvcSiteMapProvider - Part 4: The IAclModule
- Inside the MvcSiteMapProvider - Part 5: The ISiteMapNodeUrlResolver
- Styling MvcSiteMapProvider with CSS
- Using MvcSiteMapProvider with Twitter Bootstrap
- ASP.NET MVC Menu using Site Map Provider & Bootstrap Navbar