[英]classe active with @html.ActionLink
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 下面提到的是使用ViewContext.RouteData
的代码,还请确保您在<li>
标记而不是<a>
标记上应用class="active"
<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 让我知道这是否有帮助
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.