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 is something a little different, use a FilterAttribute:
[NavigationLocationFilter("Products")]
public ViewResult List()
{
return View();
}
...
public class NavigationLocationFilterAttribute : ActionFilterAttribute
{
public string CurrentLocation { get; set; }
public NavigationLocationFilterAttribute(string currentLocation)
{
CurrentLocation = currentLocation;
}
public override void OnActionExecuting(ActionExecutingContext filterContext)
{
var controller = (Controller)filterContext.Controller;
controller.ViewData.Add("NavigationLocation", CurrentLocation);
}
}
...
And in the view:
<%= ViewData["NavigationLocation"] %>