Can we call the Method of a controller from another controller in asp.net MVC?

后端 未结 6 1059
攒了一身酷
攒了一身酷 2021-02-07 10:45

Can we call the Method of a controller from another controller in asp.net MVC?

6条回答
  •  长情又很酷
    2021-02-07 11:08

    Technically, yes. You can call a static method of a controller or initialize an instance of a controller to call its instance methods.

    This, however, makes little sense. The methods of a controller are meant to be invoked by routing engine indirectly. If you feel the need to directly call an action method of another controller, it is a sign you need some redesign to do.

提交回复
热议问题