Programmatically get/display all controllers and actions name in C#,ASP.Net MVC Core

In this tutorial i am going to explain about how to Programmatically get/display all controllers and actions name in C#,ASP.Net MVC Core. In my previous tutorial i have explained about

In this tutorial you will learn

  • asp.net mvc list all controllers and actions
  • asp net mvc get all routes
  • asp net core get controller name
  • web api list all routes
  • c# get all controller actions
  • web api get all registered routes
  • asp net mvc reflection controllers
  • reflection get all controllers

Implementation :

Now we will see the implementation of how to Programmatically get/display all controllers and actions name in C#,ASP.Net MVC Core.

First open a visual studio and create a new asp.net mvc or asp.net core project. Create Some sample controllers and actions with some attribute for testing purpose. And finally in any one of the controller create a action method called GetAllControllerActions(). Here i have created it in home controller. Include below namespaces in homecontroller.cs

Now create a model called ControllerActions in the model folder or in the controller itself. In my example i have created in controller itself. Add the below properties in ControllerActions class.

Now paste the below code in GetAllControllerActions() action method. This code is used to Programmatically get/display all controllers and actions name in C#,ASP.Net MVC Core.

Now right click on GetAllControllerActions() action method and choose Add View method. Choose list template and ControllerActions model in model class and click Add. And then I have changed the generated view into below code. I have just deleted unwanted code.

Output:

Now if you run the program you can see the output of how to Programmatically get/display all controllers and actions name in C#,ASP.Net MVC Core like below.

Programmatically get display all controllers and actions name in C#,ASP.Net MVC Core

Source Code:

Source code of how to Programmatically get/display all controllers and actions name in C#,ASP.Net MVC Core

 

 

 

Conclusion:

Hope you learned how to Programmatically get/display all controllers and actions name in C#,ASP.Net MVC Core. Do you like this tutorial? Help us to improve. Please post your comments and feedback below.

Leave a Reply

Your email address will not be published. Required fields are marked *