-2

When, home menu is active (selected), render this

<li class="active"><a href = "~/Home" >Home</a></li>

Otherwise, when home menu is inactive (not selected), render this

<li><a href = "~/Home" >Home</a></li>
001
  • 62,807
  • 94
  • 230
  • 350
  • There a multiple ways - using a `HtmlHelper` extension method that returns a class name based on the current route, or assignung a value to `ViewBag` and using some javascript to set it, etc etc. –  Sep 15 '17 at 05:41
  • What do you mean by "home menu is active"..? Do you refer to an action inside your controller? – Angel D. Sep 15 '17 at 05:44
  • The extension method in dom's answer to [this question](https://stackoverflow.com/questions/20410623/how-to-add-active-class-to-html-actionlink-in-asp-net-mvc) is one example –  Sep 15 '17 at 05:45

1 Answers1

0

Try this type it May Help You.

<li class="@(ViewContext.RouteData.Values["Action"].ToString() == "Home" ? "active" : "")"><a href = "~/Home" >Home</a></li>
Aravinthan M
  • 835
  • 1
  • 9
  • 24