Brendan Vogt Brendan Vogt - 2 months ago 17
ASP.NET (C#) Question

How to render a partial view asynchronously

Can a partial view be rendered asynchronously?

I have a partial view that needs to render blog posts. The blog posts are returned asynchronously.

In my

file I render my partial footer
. In
I have the following markup:

@Html.Action("FooterLatestBlogPosts", "Common")

So in my
controller I have the following action method:

public async Task<ActionResult> FooterLatestBlogPosts()
List<ArticleDTO> articleDTOs = await articleTask.GetAllAsync();

return PartialView(articleDTOs);

In my
partial view I have the following:

@model List<MyProject.Application.DTO.ArticleDTO>
@if (Model.Count > 0)
<ul class="list-unstyled">
@foreach (var articleDTO in Model)

I'm getting an error:

Error executing child request for handler 'System.Web.Mvc.HttpHandlerUtil+ServerExecuteHttpHandlerAsyncWrapper'

Should I rather just create a synchronous mthod to bring back my data?


I went with the answer in the post that @buffjape suggested:

Async PartialView causes "HttpServerUtility.Execute blocked..." exception

I changed my methods all to synchronous.