Getting both Action and Controller Names together in Asp.Net MVC.

vishalneeraj-24503
Posted by vishalneeraj-24503 under ASP.NET MVC category on | Points: 40 | Views : 2092
We have a RouteData object which is a Dictionary object with two items inside it such as Controller and Action which is used to find information regarding Action and Controller.
RouteData object has Value method or we can say we have to pass key name as action and controller.

Below is the code to find Action and Controller Names:-
if (RouteData.Values["controller"] != null)
{
var mvc_controller = Convert.ToString(RouteData.Values["controller"]);
}

if (RouteData.Values["action"] != null)
{
var mvc_action = Convert.ToString(RouteData.Values["action"]);
}

Comments or Responses

Login to post response