MVC 异步和常规之间的区别

MVC difference between async and regular

async Task<> 和没有 async Task<> 有什么区别?这有区别吗,这就像使用 jquery ajax 一样吗?

   [HttpPost]
    [ValidateAntiForgeryToken]
    public async Task<ActionResult> SetPassword(SetPasswordViewModel model)
    {

        // If we got this far, something failed, redisplay form
        return View(model);
    }

对比

    [HttpPost]
    [ValidateAntiForgeryToken]
    public ActionResult SetPassword(SetPasswordViewModel model)
    {

        // If we got this far, something failed, redisplay form
        return View(model);
    }

异步控制器方法有利于长 运行 的方法。例如,进行昂贵的数据库查询或后端服务调用的方法。

它不同于ajax。这会导致您的控制器方法在新线程中执行,从而为 Web 服务器释放线程来处理请求。

我知道这不是最好的描述,但您可以在这里找到更多信息:

http://msdn.microsoft.com/en-us/library/ee728598%28v=vs.100%29.aspx