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

后端 未结 2 1531
名媛妹妹
名媛妹妹 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.

    0 讨论(0)
  • 2020-12-03 04:50

    This is done in an internal class in the System.Web.Mvc assembly called System.Web.Mvc.ControllerTypeCache.

    By the way, action methods are not required to return ActionResult. They can return void happily, for instance.

    0 讨论(0)
提交回复
热议问题