Reputation: 2011
I am using the nuget package MvcSiteMapProvider to create my menu structure. I have a tab called "DTLSA" and when users hover that I only want "Application Status" and "Apply Now" visible. So from "Personnel" and below would all be hidden in the structure. However, if a user is on "Personnel" or any of the other pages I want the "DTLSA" to have the css class "active" applied to it (that's the only reason why I have them here). If I set the visibility=!*
it doesn't set the DTLSA tab as active. Is it possible to set it active but keep those options from being displayed in the dropdown?
Mvc.sitemap:
<mvcSiteMapNode title="DTLSA" url="#">
<mvcSiteMapNode title="Application Status" controller="application" action="index" area="" />
<mvcSiteMapNode title="Apply Now" controller="application" action="applynow" preservedRouteParameters="applicationId" area="" />
<mvcSiteMapNode title="Personnel" controller="application" action="personnel" preservedRouteParameters="applicationId" area="" visibility="!*" />
<mvcSiteMapNode title="Review" controller="application" action="review" area="" preservedRouteParameters="applicationId" visibility="!*" />
<mvcSiteMapNode title="Checkout" controller="application" action="checkout" area="" preservedRouteParameters="applicationId" visibility="!*" />
<mvcSiteMapNode title="Confirmation" controller="application" action="confirmation" preservedRouteParameters="applicationId" area="" visibility="!*" />
</mvcSiteMapNode>
MenuHelperModel display template:
@model MvcSiteMapProvider.Web.Html.Models.MenuHelperModel
@using System.Web.Mvc.Html
@using MvcSiteMapProvider.Web.Html.Models
<ul class="nav navbar-nav navbar-right">
@foreach (var node in Model.Nodes) {
<li class="@(node.IsCurrentNode || node.Children.Any(n => n.IsCurrentNode) ? "active" : "") @(node.Children.Any() ? "dropdown" : "")">@Html.DisplayFor(m => node)
@if (node.Children.Any()) {
@Html.DisplayFor(m => node.Children)
}
</li>
}
Upvotes: 0
Views: 357
Reputation: 56869
You can use the node.IsInCurrentPath
property to determine if the node is part of the current path (whether it has visible children or not).
@model MvcSiteMapProvider.Web.Html.Models.MenuHelperModel
@using System.Web.Mvc.Html
@using MvcSiteMapProvider.Web.Html.Models
<ul class="nav navbar-nav navbar-right">
@foreach (var node in Model.Nodes) {
<li class="@(node.IsInCurrentPath && !node.IsRootNode ? "active" : "") @(node.Children.Any() ? "dropdown" : "")">@Html.DisplayFor(m => node)
@if (node.Children.Any()) {
@Html.DisplayFor(m => node.Children)
}
</li>
}
Upvotes: 1