How to add “active” class to Html.ActionLink in ASP.NET MVC

Total Post:1

Points:7
 374  View(s)
Ratings:
Rate this:

I want to add the active class in bootstrap navabar

<ul class="nav navbar-nav">

  <li>@Html.ActionLink("Home", "Index", "Home", null, new {@class="active"})</li>
  <li>@Html.ActionLink("About", "About", "Home")</li>
  <li>@Html.ActionLink("Contact", "Contact", "Home")</li>
</ul>


  1. Post:2

    Points:14
    Re: How to add “active” class to Html.ActionLink in ASP.NET MVC

    You have to add active class in li

    <ul class="nav navbar-nav">
    
        <li class="active">@Html.ActionLink("Home", "Index", "Home")</li>
        <li>@Html.ActionLink("About", "About", "Home")</li>
        <li>@Html.ActionLink("Contact", "Contact", "Home")</li>
    </ul>

Answer

NEWSLETTER

Enter your email address here always to be updated. We promise not to spam!