I wanted to set a CSS class in my master page, which depends on the current controller and action. I can get to the current controller via ViewContext.Controller.GetType().Name, but how do I get the current action (e.g. Index, Show etc.)?
I wanted to set a CSS class in my master page, which depends on
Share
Use the
ViewContextand look at theRouteDatacollection to extract both the controller and action elements. But I think setting some data variable that indicates the application context (e.g., ‘editmode’ or ‘error’) rather than controller/action reduces the coupling between your views and controllers.