1

I need to get all controller names and ActionNames in my MenuController to show in Dropdown.

For Example

 ViewBag.ActionNames = GetActionNames();
 ViewBag.ControllerNames = GetControllerNames();

How do I get all controller names in ASP.NET MVC?

George Stocker
  • 56,270
  • 29
  • 173
  • 234
ineffable p
  • 1,161
  • 2
  • 20
  • 44
  • You can use .Net Reflection to get all the controller names in your controller namespace, and also, action names – Paritosh Jul 08 '13 at 10:46
  • Try this public static List GetControllerNames() { List controllerNames = new List(); GetSubClasses().ForEach( type => controllerNames.Add(type.Name)); return controllerNames; } private static List GetSubClasses() { return Assembly.GetCallingAssembly().GetTypes().Where( type => type.IsSubclassOf(typeof(T))).ToList(); } sorry I am unable to post answer – Syed Salman Raza Zaidi Jul 08 '13 at 12:20

1 Answers1

-1

Call ViewContext.RouteData.GetRequiredString("action").

Hope this will help you.

Soner Gönül
  • 94,086
  • 102
  • 195
  • 339
Jack
  • 243
  • 2
  • 8