Asp.net mvc 3 MVC3控制器。重定向(字符串)

Asp.net mvc 3 MVC3控制器。重定向(字符串),asp.net-mvc-3,Asp.net Mvc 3,我的控制器中有这样一个私有函数 private UserDetails GetUserDetails(int userid) { ... if (some condition check is false) Redirect("some other page in a different subdomain"); return userDetails; } 如果条件失败,将执行重定向语句,但执行不会停止。userDetails返回给调用函数。没有重定向

我的控制器中有这样一个私有函数

private UserDetails GetUserDetails(int userid)
{
    ...
    if (some condition check is false)
        Redirect("some other page in a different subdomain");

    return userDetails;
}
如果条件失败,将执行重定向语句,但执行不会停止。userDetails返回给调用函数。没有重定向到其他页面


我怎样才能强制重定向?

有些情况下,您无法重定向,尽管我不确定对整套重定向的规定是什么。解决这个问题的一种方法是向视图返回一个字符串,并让javascript do
window.location(url)
强制重定向。

重定向返回一个结果-您要在操作方法中使用它,如下所示:

public ActionResult MyAction() 
{
    if (check is false) 
    {
        return Redirect("other url");
    }
    // this code won't get executed after redirect
}

看起来您应该从上面发布的函数中返回null,然后检查null和
返回重定向(“…”)
如果GetUserDetails返回null。如果失败,为什么不将null传回去,并让您的视图处理或忽略null?