List of Actions for specific controller
I have a list of controller names and would then have a list of all actions in a given controller (name, GUID).
The list of all controllers found here.
I was also re开发者_如何转开发ading List all the actions on a controller with specific attribute which would match for my purposes as I also need actions with specific attributes. But I have only the name / GUID of the selected controller, not the object itself.
My scenario: the user selects a controller (cascading dropdown-list) and then actions from this controller to configure some access (and links). Therefore I need only the actions that have a custom attribute.
You can continue using Reflection just like you did to get the Types in your assembly that inherit from Controller. Once you have the Type, you can enumerate the methods:
foreach(MethodInfo method in myContollerType.GetMethods(BindingFlags.Public | BindingFlags.Instance))
{
}
And, then for each method, you can get all the custom attributes:
foreach (var attribute in method.GetCustomAttributes(typeof(MyAttributeType),false))
{
}
精彩评论