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

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

In this post, We manged to do this by adding a view bag parameter in asp.net mvc.

In action

public ActionResult htmlbeautifier()
        {
            ViewBag.Active = "2";
            return View();
        }
        [Route("html-minifier")]
        public ActionResult htmlminifier()
        {
            ViewBag.Active = "3";
            return View();
        }
<li class="@( ViewBag.Active == "2" ? "nav-item active" : "")"> <a href="/website-seo-score-checker-analyzer" class="nav-link">SEO Analyzer</a></li>
<li class="@( ViewBag.Active == "3" ? "nav-item active" : "")"> <a href="/article-list" class="nav-link">Article List</a></li>

2020-02-22