Can I get the controller from the HttpContext?

前端 未结 4 1161
被撕碎了的回忆
被撕碎了的回忆 2020-12-29 01:35

Given an HttpContext (or HttpContextBase), is there a way to get an instance of the Controller?

4条回答
  •  暗喜
    暗喜 (楼主)
    2020-12-29 01:50

    Not easily, you will basically have to first get the MvcHandler from the RouteData, then build the Controller. Even then, it won't give you the instance used to handle the action as it will be a new instance of the controller.

提交回复
热议问题