Highlight node for every action in a controller

Feb 7, 2011 at 4:14 PM
Edited Feb 7, 2011 at 4:15 PM


I have a sitemap in my admin area that defines several controllers like this: 

<?xml version="1.0" encoding="utf-8" ?>
<mvcSiteMap xmlns="http://mvcsitemap.codeplex.com/schemas/MvcSiteMap-File-3.0" enableLocalization="false">
	<mvcSiteMapNode title="Startseite" controller="Home" action="Index" changeFrequency="Monthly" updatePriority="Normal">
		<!--Main Page-->
		<!--Admin Area-->
		<mvcSiteMapNode title="Marken" controller="Brand" action="Index" area="Admin" />
		<mvcSiteMapNode title="Absperrpfosten" controller="Barrier" action="Index" area="Admin" />

I create the admin area navigation using MvcSitemap().Menu(false) and use the following DisplayTemplate to highlight the active navigation element:

<%@ Control Language="C#" Inherits="System.Web.Mvc.ViewUserControl`1[ [MvcSiteMapProvider.Web.Html.Models.MenuHelperModel,MvcSiteMapProvider] ]" %>

<%--this controls the output of the main navigation bar in the AdminArea--%>
<ul id="MainNav">
<% foreach (var node in Model.Nodes) { %>
    <%--show AdminArea nodes only--%>
    <% if (!node.Area.Equals("Admin")) { %>    
        <% continue; %>
    <% } %>
    <%--hightlight active node using a CSS class--%>
    <% if (node.IsCurrentNode) { %>    
        <li class="naviActive"><%=Html.DisplayFor(m => node)%>
    <% } %>
    <% else { %>
        <li class="naviInactive"><%=Html.DisplayFor(m => node)%>
    <% } %>
    <% if (node.Children.Any()) { %>
        <%=Html.DisplayFor(m => node.Children)%>
    <% } %>
<% } %>

My problem is that I'd like to highlight a navigation entry also when I am working in another method on the same controller. For example: If I am browsing /Admin/Brand/Edit/5, the navigation item "Marken" with the path /Admin/Brand should be highlighted.

I tried using node.IsInCurrentPath in my DisplayTemplate but that didn't work. I don't want to include paths like /edit in my sitemap. 

Any help is highly appreciated. Thanks in advance!

Feb 14, 2011 at 8:17 AM

Check the sample application;, the left side menu also does this.