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
  • 57,289
  • 29
  • 176
  • 237
ineffable p
  • 1,207
  • 2
  • 22
  • 46
  • 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
  • 97,193
  • 102
  • 206
  • 364
Jack
  • 253
  • 3
  • 8