Max
Max

Reputation: 5063

In MVC3, how to get the current controller name?

From the http context class is there a method to get the current Controller name?

Upvotes: 5

Views: 7575

Answers (1)

Jonathan
Jonathan

Reputation: 12025

Yes, you can do something like that

HttpContext.Current.Request.RequestContext.RouteData.Values["controller"].ToString();

If you're in a view, then you can do:

ViewContext.RouteData.Values["Controller"]

Upvotes: 11

Related Questions