Async PartialView raises the exception "HttpServerUtility.Execute blocked ..."
I have a partial view that is trying to extract an IEnumerable<Post> from a database using async ...
Method
public static class PostService { public static int PostsPerPage = 50; public static async Task<IEnumerable<Post>> GetRecentAsync(int page = 0) { return await entityFrameworkDbContext.Posts .ToListAsync(); } } Partialialview
public async Task<ActionResult> Recent(int page = 0) { return PartialView(await PostService.GetRecentAsync(page)); } And if I try to call him
@Html.Action("Recent", "Post") I get the following exception
HttpServerUtility.Execute is locked, waiting for the completion of the asynchronous operation.
Description: An unhandled exception occurred during the execution of the current web request. View the stack trace for more information about the error and its occurrence in the code.
Exception Details: System.InvalidOperationException: HttpServerUtility.Execute blocked, waiting for the asynchronous operation to complete.
Why am I getting this error? Shouldn't this work?
The child's actions must be performed synchronously. Issue 601 I also do not know of recent updates to the current MVC libraries that enable this functionality.
Commentary on 601 release, hints at adding this functionality to MVC vNext, aka. MVC6. Actions with children look replaceable with ViewComponent , which can be called asynchronously from the view, as shown below. Full examples here and here.
<div> @await Component.InvokeAsync("YourComponent") </div> Learn more about MVC6, http://www.asp.net/vnext/overview/aspnet-vnext/overview
Note. This answer is just a formality, so the question can be marked as an answer.