-
Notifications
You must be signed in to change notification settings - Fork 1
Specifying Node Order
As of version 4.3.0, you can set the order that the nodes will appear in the @Html.MvcSiteMap().Menu() and @Html.MvcSiteMap().SiteMap() HTML helpers. This can be done by setting the Order property or attribute of the node to an integer value. The lowest value will appear first below its parent node in the HTML helper, and the highest value will appear last. That is, the order is only relative to the other nodes that have the same parent node (the sibling nodes). If no order is specified on a node, the default is 0.
Node ordering can come in handy when you have nodes on a certain level that are configured from different sources. In this example, we demonstrate how you can add some nodes via XML, some via MvcSiteMapNodeAttribute, and some via a dynamic node provider and order them appropriately.
<mvcSiteMapNode title="Home" controller="Home" action="Index" key="Home">
<mvcSiteMapNode title="Dynamic Node Stub" dynamicNodeProvider="MyNamespace.MyOrderedDynamicNodeProvider, MyAssemblyName"/>
<mvcSiteMapNode title="Node 6" controller="Home" action="Node6" order="6"/>
<mvcSiteMapNode title="Node 3" controller="Home" action="Node3" order="3"/>
<mvcSiteMapNode title="Node 8" controller="Home" action="Node8" order="8"/>
</mvcSiteMapNode>
public class MyOrderedDynamicNodeProvider
: DynamicNodeProviderBase
{
public override IEnumerable<DynamicNode> GetDynamicNodeCollection(ISiteMapNode node)
{
var nodes = new List<DynamicNode>();
var node9 = new DynamicNode("Node9", "Home", "Node 9", "", "Node9");
node9.Order = 9;
nodes.Add(node9);
var node2 = new DynamicNode("Node2", "Home", "Node 2", "", "Node2");
node2.Order = 2;
nodes.Add(node2);
var node5 = new DynamicNode("Node5", "Home", "Node 5", "", "Node5");
node5.Order = 5;
nodes.Add(node5);
return nodes;
}
}
public class HomeController : Controller
{
public ActionResult Index()
{
ViewBag.Message = "Modify this template to jump-start your ASP.NET MVC application.";
return View();
}
[MvcSiteMapNode(Title = "Node 1", ParentKey = "Home", Key = "Node1", Order = 1)]
public ActionResult Node1
{
ViewBag.Message = "Node 1 page.";
return View();
}
public ActionResult Node2
{
ViewBag.Message = "Node 2 page.";
return View();
}
public ActionResult Node3
{
ViewBag.Message = "Node 3 page.";
return View();
}
[MvcSiteMapNode(Title = "Node 4", ParentKey = "Home", Key = "Node4", Order = 4)]
public ActionResult Node4
{
ViewBag.Message = "Node 4 page.";
return View();
}
public ActionResult Node5
{
ViewBag.Message = "Node 5 page.";
return View();
}
public ActionResult Node6
{
ViewBag.Message = "Node 6 page.";
return View();
}
[MvcSiteMapNode(Title = "Node 7", ParentKey = "Home", Key = "Node7", Order = 7)]
public ActionResult Node7
{
ViewBag.Message = "Node 7 page.";
return View();
}
public ActionResult Node8
{
ViewBag.Message = "Node 8 page.";
return View();
}
public ActionResult Node9
{
ViewBag.Message = "Node 9 page.";
return View();
}
}
If you were to put the above configuration into a project and add a @Html.MvcSiteMap().SiteMap() HTML helper to your /Views/Shared/_Layout.cshtml view, you would see the nodes listed in order.
- Home
- Node 1
- Node 2
- Node 3
- Node 4
- Node 5
- Node 6
- Node 7
- Node 8
- Node 9
Note: In versions prior to 4.3.0, the Order property existed on the MvcSiteMapNodeAttribute but its purpose was to ensure that processing of the nodes occurred in the correct order so the parent node was added to the SiteMap before the child node. This was sometimes necessary to make the ParentKey match. Although this property has been re-purposed in 4.3.0, it is safe to upgrade an older configuration without affecting the node order even though the Order property setting may no longer be strictly required.
- [Wiki Home] (.)
- [Release Notes] (https://github.com/maartenba/MvcSiteMapProvider/releases)
Want to contribute? See our [Contributing to MvcSiteMapProvider] (https://github.com/maartenba/MvcSiteMapProvider/blob/master/CONTRIBUTING.md) guide.
- [Upgrading from v3 to v4] (Upgrading-from-v3-to-v4)
- [Routing Basics] (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] (Multiple-Sitemaps-in-One-Application)
- [Security Trimming] (Security-Trimming)
[Version 3.x Documentation] (Version-3.x-Documentation)
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] (http://www.shiningtreasures.com/post/2013/08/07/MvcSiteMapProvider-40-a-test-drive)
- [MvcSiteMapProvider 4.0 - SEO Features Tutorial] (http://www.shiningtreasures.com/post/2013/08/10/mvcsitemapprovider-4-seo-features)
- [How to Make MvcSiteMapProvider Remember a User’s Position] (http://www.shiningtreasures.com/post/2013/09/02/how-to-make-mvcsitemapprovider-remember-a-user-position)
- [MvcSiteMapProvider 4.0 - Cache Configuration] (http://www.shiningtreasures.com/post/2013/08/11/mvcsitemapprovider-4-cache-configuration)
- [MvcSiteMapProvider 4.0 - Extending the Cache] (http://www.shiningtreasures.com/post/2013/08/13/mvcsitemapprovider-4-extending-the-cache)
- [MvcSiteMapProvider 4.0 - Unit Testing with the SiteMaps Static Methods] (http://www.shiningtreasures.com/post/2013/08/14/mvcsitemapprovider-4-unit-testing-with-the-sitemaps-static-methods)
- [Debugging an MvcSiteMapProvider Configuration] (http://www.shiningtreasures.com/post/2013/08/21/debugging-an-mvcsitemapprovider-configuration)
- [Converting from C# to Vb MvcSiteMapProvider] (http://www.developerfusion.com/thread/112710/converting-from-c-to-vb-mvcsitemapprovider/)
- [NightOwl888's MvcSiteMapProvider Demos] (https://github.com/NightOwl888?tab=repositories) - Filter for "MvcSiteMapProvider" to see the most relevant.
- [MvcSiteMapProvider Tutorial and Examples] (http://edspencer.me.uk/2011/02/10/mvc-sitemap-provider-tutorial/)
- [MvcSiteMapProvider Tutorial 2 - Breadcrumbs] (http://edspencer.me.uk/2011/09/20/mvc-sitemap-provider-tutorial-2-breadcrumbs/)
- [Getting Started with MvcSiteMapProvider] (http://blog.danstuken.com/2011/04/29/getting-started-with-mvcsitemapprovider/)
- [Inside the MvcSiteMapProvider - Part 1] (http://xharze.blogspot.com/2012/04/inside-mvcsitemapprovider-part-1.html)
- [Inside the MvcSiteMapProvider - Part 2: Dynamic node providers] (http://xharze.blogspot.com/2012/04/inside-mvcsitemapprovider-part-2.html)
- [Inside the MvcSiteMapProvider - Part 3: The ISiteMapVisibilityProvider] (http://xharze.blogspot.com/2012/04/inside-mvcsitemapprovider-part-3.html)
- [Inside the MvcSiteMapProvider - Part 4: The IAclModule] (http://xharze.blogspot.com/2012/04/inside-mvcsitemapprovider-part-4.html)
- [Inside the MvcSiteMapProvider - Part 5: The ISiteMapNodeUrlResolver] (http://xharze.blogspot.com/2012/04/inside-mvcsitemapprovider-part-5.html)
- [Styling MvcSiteMapProvider with CSS] (http://tutsblog.net/styling-mvc-sitemap-provider-with-css/)
- [Using MvcSiteMapProvider with Twitter Bootstrap] (http://codingit.wordpress.com/2013/05/03/using-mvcsitemapprovider-with-twitter-bootstrap/)
- [ASP.NET MVC Menu using Site Map Provider & Bootstrap Navbar] (http://joeylicc.wordpress.com/2013/06/04/asp-net-mvc-menu-using-site-map-provider-bootstrap-navbar/)
- [StackOverflow MvcSiteMapProvider] (http://stackoverflow.com/questions/tagged/mvcsitemapprovider)
- [StackOverflow MvcSiteMap] (http://stackoverflow.com/questions/tagged/mvcsitemap)
- [StackOverflow ASP.NET MVC SiteMap] (http://stackoverflow.com/questions/tagged/asp.net-mvc-sitemap)
- [CodePlex Discussion Forum (no longer maintained)] (http://mvcsitemap.codeplex.com/discussions/topics/general?size=2147483647)
- [Telerik Forum] (http://www.telerik.com/search.aspx?insection=False&start=0&client=telerik_developer_tools&q=MvcSiteMapProvider&sid=1)
- [maartenba's blog] (http://blog.maartenballiauw.be/search.aspx?q=mvcsitemapprovider)
- [NightOwl888's blog] (http://www.shiningtreasures.com/category/MvcSiteMapProvider)