Display a view from another controller in ASP.NET MVC

后端 未结 7 1199
孤街浪徒
孤街浪徒 2020-11-29 16:06

Is it possible to display a view from another controller?

Say for example I have a CategoriesController and a Category/NotFound.aspx view.

7条回答
  •  我在风中等你
    2020-11-29 16:15

    With this code you can obtain any controller:

    var controller = DependencyResolver.Current.GetService();
    controller.ControllerContext = new ControllerContext(this.Request.RequestContext, 
    controller);
    

提交回复
热议问题