undefined
undefined

Reputation: 513

Navigation bar as a partial view. What about "active" class

I've got a navigation bar as a partial view - it contains page links. Everything works fine, but how do I use the <li class="active"> now? Since there is no controller, I can't use the active class to highlight on which page user is currently on. Any ideas?

Upvotes: 0

Views: 1430

Answers (2)

Abdul Rahman
Abdul Rahman

Reputation: 1

I am faced same Issue Use the Following Code Given Below

<a class="@(ViewContext.RouteData.Values["Action"].ToString() == "HomePage" ? "active" : "") " [email protected]("ActionName","ControllerName" > </a>
// If the link in the Action and 
// HomePage is My current Active Page
// Active is Class  

Upvotes: -1

Alex Suleap
Alex Suleap

Reputation: 569

To detect on which page you should set the active class you can check the ViewContext.RouteData. Ex:

<li class="@(ViewContext.RouteData.Values["Action"].ToString() == "Index" ? "active" : "")">@Html.ActionLink("Home", "Index", "Home")</li>
<li class="@(ViewContext.RouteData.Values["Action"].ToString() == "Action1" ? "active" : "")">@Html.ActionLink("Action1", "Action1", "Home")</li>
 ..................

Upvotes: 2

Related Questions