When you create a new MVC project it creates a Site.master with the following markup:
First Make a Helper Class and HTML Helper method
public static string IsActive(this HtmlHelper html,string control,string action)
{
var routeData = html.ViewContext.RouteData;
var routeAction = (string)routeData.Values["action"];
var routeControl = (string)routeData.Values["controller"];
// both must match
var returnActive = control == routeControl &&
action == routeAction;
return returnActive ? "active" : "";
}
And in View or Layour Section Just Call the Helper Method with appropriate Conntroller and Action.
@using YourNamespace.HtmlHelpermethodName
this will add "active" string in class attribute and it will show like