I've a SuperController
which will be inherited from all the controllers. In the constructor I'm trying to populate the ViewData using the ControllerName and the ActionName.
I'm not going to pass the ControllerName and the ActionName as the ViewData. I've a method that needs the ControllerName and the ActionName and I need to pass the return value of the method as the ViewData.
How can I do that?
Don't use ViewData
. Use this in your Site.Master instead:
<%= ViewContext.RouteData.Values["Controller"] %>
<%= ViewContext.RouteData.Values["Action"] %>
SO - Getting the name of the controller and action method in the view in ASP.Net MVC