I need to determine if I\'m on a particular view. My use case is that I\'d like to decorate navigation elements with an \"on\" class for the current view. Is there a built in
Here what i am using. I think this is actually generated by the MVC project template in VS:
public static bool IsCurrentAction(this HtmlHelper helper, string actionName, string controllerName)
{
string currentControllerName = (string)helper.ViewContext.RouteData.Values["controller"];
string currentActionName = (string)helper.ViewContext.RouteData.Values["action"];
if (currentControllerName.Equals(controllerName, StringComparison.CurrentCultureIgnoreCase) && currentActionName.Equals(actionName, StringComparison.CurrentCultureIgnoreCase))
return true;
return false;
}