如果控制器操作重定向到外部URL,您在函数中返回什么?

leo*_*ora 3 asp.net-mvc hyperlink

我有一个功能,我不清楚我应该从这回来?

public ActionResult LoadExternalURL()
{
         Response.Redirect("http://www.google.com");

         // what do i return here ??
}
Run Code Online (Sandbox Code Playgroud)

Joh*_*ter 5

而不是调用Response.Redirect,更容易使用内置的RedirectResult ActionResult,如下所示: -

return Redirect("http://www.google.com");
Run Code Online (Sandbox Code Playgroud)

这也将提高代码的可测试性(您不必嘲笑模拟HTTP上下文),而只需测试返回的操作结果的Url属性.