且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

如何在ASP.Net MVC中使用“任务"重定向到操作

更新时间:2021-08-17 22:13:01

您需要将UpdateUser操作的返回类型从Task<ActionResult>更改为Task<RedirectToRouteResult>

You need to change the return type of UpdateUser action from Task<ActionResult> to Task<RedirectToRouteResult>

public Task<RedirectToRouteResult> UpdateUser(ProfileModel model)
{
  return Task.Factory.StartNew(showMethod).ContinueWith(
    t => {
      return RedirectToAction("ViewUser","UserProfile");
  });
}

或者您可以使用ActionResult显式设置ContinueWith方法的泛型类型参数,如下所示:

Or you could explicitly set the generic type argument of ContinueWith method with ActionResult, like this:

public Task<ActionResult> UpdateUser(ProfileModel model)
{
  return Task.Factory.StartNew(showMethod).ContinueWith<ActionResult>(
    t => {
      return RedirectToAction("ViewUser","UserProfile");
  });
}