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.)?
C# – How to return the current action in an ASP.NET MVC view
asp.net-mvcc
Related Topic
- C# – How to get the current user in ASP.NET MVC
- C# – Can you overload controller methods in ASP.NET MVC
- C# – Proper use of the IDisposable interface
- C# – How to remedy “The breakpoint will not currently be hit. No symbols have been loaded for this document.” warning
- C# – How to get the client’s IP address in ASP.NET MVC
- C# – How to Sort a List
by a property in the object - C# – File Upload ASP.NET MVC 3.0
- Scala: list.flatten: no implicit argument matching parameter type (Any) = > Iterable[Any] was found
Best Answer
In the RC you can also extract route data like the action method name like this
Update for MVC 3
Update for MVC 4
Update for MVC 4.5