MVC4 .NET 4.5 异步操作方法不重定向 [英] MVC4 .NET 4.5 async action method does not redirect

查看:31
本文介绍了MVC4 .NET 4.5 异步操作方法不重定向的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I am trying to implement a task action method in my MVC 4 application. Everything works on the back in, but it is not redirecting.

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
    }
}

推荐答案

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

I was able to get it working after making the Action I was directing it to an async action as well. I am guessing if you have any async action method redirecting to another then that redirect must be async as well.

这里只是一个简单的例子

Here is just a quick example

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();
}

这篇关于MVC4 .NET 4.5 异步操作方法不重定向的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆