在一个异步主视图渲染一个异步分部视图时提示上述错误,主视图出错位置(行2):
1 <div class="am-topbar-right"> 2 @Html.Action("_Identity", "Shared") 3 </div>
主视图后台代码:
public async Task<ActionResult> Explore() { ViewBag.LatestClasses = await base.Service.ClassService.GetEntities(); ViewBag.RecommendedClasses = await base.Service.ClassService.SelectWhere(x => x.IsRecommend == true); return View(); }
分部视图后台代码:
1 public async Task<ActionResult> _Identity() 2 { 3 // 获取登录账户的班级 4 if (Session["CurrentAccount"] != null) 5 { 6 Person person = Session["CurrentAccount"] as Person; 7 Relation relation = (await base.Service.RelationService.SelectWhere(x => x.PersonId == person.PersonId)).FirstOrDefault(); 8 if (relation != null) 9 { 10 ViewBag.AccountClass = (await base.Service.ClassService.SelectWhere(x => x.ClassId == relation.ClassId)).FirstOrDefault(); 11 } 12 } 13 return PartialView(); 14 }
对应的英文错误信息是:
HttpServerUtility.Execute blocked while waiting for an asynchronous operation to complete.
MVC 5不支持分部视图的异步,MVC 6支持。
参考:Async PartialView causes “HttpServerUtility.Execute blocked…” exception
http://www.cnblogs.com/dunitian/p/5481138.html