MVC4 .NET 4.5 异步操作方法不重定向

use*_*883 4 c# asp.net-mvc async-await .net-4.5

我正在尝试在我的 MVC 4 应用程序中实现一个任务操作方法。一切都在后面工作,但它不是重定向。

public class AccountController : AsyncController 
{
    [HttpPost]
    [AllowAnonymous]
    public async Task<ActionResult> Login(LoginModel model, string returnUrl)
    {
        var client = new ClientHelper("login");
        account = await client.CallActionType<LoginModel, Account>(EnumHelpers.HttpType.Post, model);

        if (account != null)
        {
            validLogin = true;
        }

        return Redirect(returnUrl); // This is called but the page does not redirect, just sits a load
    }
}
Run Code Online (Sandbox Code Playgroud)

use*_*883 5

在制作动作后,我能够让它工作,我也将它定向到异步动作。我猜如果您有任何异步操作方法重定向到另一个,那么该重定向也必须是异步的。

这只是一个简单的例子

public async Task<ActionResult> Login(LoginModel model) {
    //You would do some async work here like I was doing.

    return RedirectToAction("Action","Controller");//The action must be async as well
}
public async Task<ActionResult> Action() {//This must be an async task 
    return View();
}
Run Code Online (Sandbox Code Playgroud)