MVC4 .NET 4.5的异步操作方法不重定向 [英] MVC4 .NET 4.5 async action method does not redirect
本文介绍了MVC4 .NET 4.5的异步操作方法不重定向的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想实现我的MVC应用4任务操作方法。一切工作在后面,但它不是重定向。
公共类的AccountController:AsyncController
{
[HttpPost]
[使用AllowAnonymous]
公共异步任务<&的ActionResult GT;登录(LoginModel型号,串RETURNURL)
{
VAR的客户=新ClientHelper(登录);
账户=等待client.CallActionType< LoginModel,帐户>(EnumHelpers.HttpType.Post,模型); 如果(帐户!= NULL)
{
validLogin = TRUE;
} 返回重定向(RETURNURL); //这就是所谓但是页面不重定向,只是坐在负载
}
}
解决方案
我是能够得到使我被它引导到一个异步操作,以及操作后,它的工作。我猜,如果您有任何异步操作方法重定向到另一个然后重定向必须是异步以及
这里只是一个简单的例子
公共异步任务<&的ActionResult GT;登录(LoginModel模型){
//你会在这里做了一些工作,异步像我在做什么。 返回RedirectToAction(动作,控制器); //动作必须是异步以及
}
公共异步任务<&的ActionResult GT;行动(){//这必须是一个异步任务
返回查看();
}
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
}
}
解决方案
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屋!
查看全文