How to simulate Server.Transfer in ASP.NET MVC?

后端 未结 14 1592
死守一世寂寞
死守一世寂寞 2020-11-22 12:00

In ASP.NET MVC you can return a redirect ActionResult quite easily :

 return RedirectToAction(\"Index\");

 or

 return RedirectToRoute(new { controller = \"         


        
14条回答
  •  眼角桃花
    2020-11-22 12:40

    You could new up the other controller and invoke the action method returning the result. This will require you to place your view into the shared folder however.

    I'm not sure if this is what you meant by duplicate but:

    return new HomeController().Index();
    

    Edit

    Another option might be to create your own ControllerFactory, this way you can determine which controller to create.

提交回复
热议问题