异步任务<>和没有它有什么区别?它有什么区别吗?这就像使用 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);
}
最佳答案
异步 Controller 方法对于长时间运行的方法是有益的。例如,进行昂贵的数据库查询或后端服务调用的方法。
它与ajax不同。这会导致您的 Controller 方法在新线程中执行,从而释放 Web 服务器的线程来处理请求。
我知道这不是最好的描述,但您可以在这里找到更多信息:
http://msdn.microsoft.com/en-us/library/ee728598%28v=vs.100%29.aspx
关于asp.net-mvc - MVC 异步和常规之间的区别,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27959271/