How could I write code to get all the action names from a controller in asp.net MVC?
I want to automatically list all the action names from a controller.
Does an
There's no generic solution for this, because I could write a custom attribute derived from ActionNameSelectorAttribute
and override IsValidName
with any custom code, even code that compares the name to a random GUID. There is no way for you to know, in this case, which action name the attribute will accept.
If you constrain your solution to only considering the method name or the built-in ActionNameAttribute
then you can reflect over the class to get all the names of public methods that return an ActionResult
and check whether they have an ActionNameAttribute
whose Name
property overrides the method name.