Faced with the problem of rendering asynchronous methods. For example, there is a template in which we embed a partial view.

<ul class="nav navbar-nav navbar-right"> @{ Html.RenderAction("PartialInfo", "Profile"); } (1) </ul> 

The PartialInfo method is asynchronous.

 [ChildActionOnly] public async Task<PartialViewResult> PartialInfo() { var user = await userService.GetByEmailAsync(User.Identity.Name); ... 

During rendering, line (1) crashes

HttpServerUtility.Execute is blocked until the end of the asynchronous operation.

I would like to know why an error occurs and why the developers have banned the asynchronous execution of methods for insertion.


ps I know that if you change to the synchronous version, everything will be ok

  • and how do you even imagine it? This means that the page is rendered (and it is rendered almost instantaneously, because it is assumed that the data are already ready), and in the middle of the bang a stream started for the new action, the page is then rendered and waits until the stream is completed and the content will be in place? why logic to carry in the view? in MVC 6, however, similar functionality is in view-components - teran
  • @teran this was rendered because there is a block of information on every page. I rendered it in layout. - Vadim Prokopchuk

1 answer 1

Asynchronous rendering of child action or partial views is not supported in ASP.NET MVC. No

  • It was immediately clear. I would like to know what caused this and what prerequisites served to make this decision - Vadim Prokopchuk