Get ControllerName and ActionName and populate the ViewData in Master Page?

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

Leave a Comment