get active class asp core 3

asp core 3 -- Posted on Nov. 17, 2020

get active class asp core 3

              
                public static string IsActive(this IHtmlHelper html,
                                  string control,
                                  string action, string Path)
        {
            string url_link = "/" + control + "/" + action;
            if (action.ToLower() == "index")
            {
                url_link = "/" + control;
            }

            if (url_link == Path)
            {
                return "active";
            }
            return "";
        }


usage  inside html 

                            <a class='nav-link @Html.IsActive("controller" , "method", Context.Request.Path)'  asp-controller="cms" asp-action="index">
                              Dashboard <span class="sr-only">(current)</span>
                            </a>
                  
   
            

Related Posts