Accessing the list of Controllers/Actions in an ASP.NET MVC application

后端 未结 2 1540
名媛妹妹
名媛妹妹 2020-12-03 04:09

We know that behind the scenes, the ASP.NET MVC framework will use reflection to determine what controllers/actions are available to be executed, based on which classes der

2条回答
  •  北海茫月
    2020-12-03 04:48

    new ReflectedControllerDescriptor(typeof(TController)).GetCanonicalActions() will return a collection of ActionDescriptor objects showing all the actions on the controller. It's not smart enough to understand things like selection attributes or naming attributes, so not every action it returns is guaranteed to be web-callable. But if you need to execute the actions directly, you can call ActionDescriptor.Execute() on any action of interest to you.

提交回复
热议问题