Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

In MVC3, how to get the current controller name?

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

like image 403
Max Avatar asked Jan 22 '13 16:01

Max


1 Answers

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"]
like image 98
Jonathan Avatar answered Sep 18 '22 21:09

Jonathan