Press Ctrl / CMD + C to copy this to your clipboard.
This post will be reported to the moderators as potential spam to be looked at
Hi,
I have the following topNavigation.cshtml which works nicely for top level pages, keeping the main-active class applied to the current menu item.
<ul> @{ string style=""; } @if(Model.Name=="Welcome"){style = " class=\"main-active\"";} <li @Html.Raw(style)> <a href="/Welcome" title="Welcome">Welcome</a> </li> @foreach (var page in Model.AncestorOrSelf(1).Children.Where("Visible")) { style=""; if(([email protected])){style = " class=\"main-active\"";} <li @Html.Raw(style)> <a href="@page.Url" title="@page.Name"> @page.Name </a> </li> } </ul>
I want to add something in or around here
if(([email protected])){style = " class=\"main-active\"";}
to cause the top menu item to remain highlighted when a child page is displayed as well. I can't get my head around it. Can anyone suggest something?
Regards,
Craig
This will work ................
Replace your foreach loop with the following ...........
@foreach (var item in Model.AncestorOrSelf(1).Children.Where("Visible")) { var selected = Array.IndexOf(Model.Path.Split(','), item.Id.ToString()) >= 0 ? " class=\"main-active;\"" : ""; <li @Html.Raw(selected)> <a href="@item.Url">@item.Name</a> </li> }
You could also use @foreach (var item in Model.AncestorOrSelf(1).Children.Where("Visible")) { <li class="@Model.IsDescendantOrSelf(item,"main", "")"> <a href="@item.Url" >@item.Name</a> </li> }
is working on a reply...
This forum is in read-only mode while we transition to the new forum.
You can continue this topic on the new forum by tapping the "Continue discussion" link below.
Continue discussion
Top menu active from side menu
Hi,
I have the following topNavigation.cshtml which works nicely for top level pages, keeping the main-active class applied to the current menu item.
I want to add something in or around here
to cause the top menu item to remain highlighted when a child page is displayed as well. I can't get my head around it. Can anyone suggest something?
Regards,
Craig
This will work ................
Replace your foreach loop with the following ...........
@foreach (var item in Model.AncestorOrSelf(1).Children.Where("Visible")) {
var selected = Array.IndexOf(Model.Path.Split(','), item.Id.ToString()) >= 0 ? " class=\"main-active;\"" : "";
<li @Html.Raw(selected)>
<a href="@item.Url">@item.Name</a>
</li>
}
You could also use
@foreach (var item in Model.AncestorOrSelf(1).Children.Where("Visible")) {
<li class="@Model.IsDescendantOrSelf(item,"main", "")">
<a href="@item.Url" >@item.Name</a>
</li>
}
is working on a reply...
This forum is in read-only mode while we transition to the new forum.
You can continue this topic on the new forum by tapping the "Continue discussion" link below.