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

后端 未结 14 1400
死守一世寂寞
死守一世寂寞 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:25

    Not an answer per se, but clearly the requirement would be not only for the actual navigation to "do" the equivalent functionality of Webforms Server.Transfer(), but also for all of this to be fully supported within unit testing.

    Therefore the ServerTransferResult should "look" like a RedirectToRouteResult, and be as similar as possible in terms of the class hierarchy.

    I'm thinking of doing this by looking at Reflector, and doing whatever RedirectToRouteResult class and also the various Controller base class methods do, and then "adding" the latter to the Controller via extension methods. Maybe these could be static methods within the same class, for ease/laziness of downloading?

    If I get round to doing this I'll post it up, otherwise maybe somebody else might beat me to it!

提交回复
热议问题