I'm having a problem to set the classes active with a specific color:
@Html.ActionLink("Fr", "Index")| @Html.ActionLink("Eng", "Index")
I tried using a helpers but it does not work.
Mentioned below is the code making use of ViewContext.RouteData
, also make sure you are applying the class="active"
on the <li>
tag and not the <a>
tag
<ul class="nav navbar-nav">
<li class="@(ViewContext.RouteData.Values["Action"].ToString() == "Index" ? "active" : "")">@Html.ActionLink("Home", "Index", "Home")</li>
<li class="@(ViewContext.RouteData.Values["Action"].ToString() == "About" ? "active" : "")">@Html.ActionLink("About", "About", "Home")</li>
<li class="@(ViewContext.RouteData.Values["Action"].ToString() == "Contact" ? "active" : "")">@Html.ActionLink("Contact", "Contact", "Home")</li>
</ul>
Let me know if this helped
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.