异步PartialView导致" HttpServerUtility.Execute受阻..."例外 [英] Async PartialView causes "HttpServerUtility.Execute blocked..." exception

查看:1250
本文介绍了异步PartialView导致" HttpServerUtility.Execute受阻..."例外的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有尝试检索局部视图的IEnumerable<邮政和GT; 从数据库中使用异步...

I have a partial view that tries to retrieve a IEnumerable<Post> from the database using async...

方法

public static class PostService
{
    public static int PostsPerPage = 50;

    public static async Task<IEnumerable<Post>> GetRecentAsync(int page = 0)
    {
        return await entityFrameworkDbContext.Posts
            .ToListAsync();
    }
}

PartialView

PartialView

public async Task<ActionResult> Recent(int page = 0)
{
    return PartialView(await PostService.GetRecentAsync(page));
}

然后,如果我尝试调用它。

And then if I try to call it

@Html.Action("Recent", "Post")

我得到下面的异常

I get the following exception

HttpServerUtility.Execute阻塞等待异步操作完成。

HttpServerUtility.Execute blocked while waiting for an asynchronous operation to complete.

说明:在当前Web请求的执行过程中发生未处理的异常。请查看有关错误的详细信息的堆栈跟踪以及它起源于code。

Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

异常详细信息:System.InvalidOperationException:HttpServerUtility.Execute在等待异步操作完成封锁

Exception Details: System.InvalidOperationException: HttpServerUtility.Execute blocked while waiting for an asynchronous operation to complete.

为什么我得到这个错误?应该不是工作?

Why do I get this error? Shouldn't it work?

推荐答案

儿童的行动必须同步调用。 发行601 我也没有意识到任何最近更新到当前的MVC库允许这种功能。

Child actions must be invoked synchronously. Issue 601 I am also not aware of any recent updates to the current MVC libraries allowing this functionality.

这是问题601评论,暗示此功能在MVC vNext添加,又名。 MVC6。儿童的行动看起来与 ViewComponent 它可以异步从如下视图被调用来代替。全例子这里和<一个href=\"https://github.com/aspnet/Mvc/blob/dev/samples/MvcSample.Web/Views/Shared/MyView.cshtml\">here

A comment on Issue 601, hints at this functionality being added in MVC vNext, aka. MVC6. Child actions look to be replaced with ViewComponent which can be invoked asynchronously from a view as below. Full examples here and here

<div>
@await Component.InvokeAsync("YourComponent")
</div>

更多关于MVC6退房,<一个href=\"http://www.asp.net/vnext/overview/aspnet-vnext/overview\">http://www.asp.net/vnext/overview/aspnet-vnext/overview

请注意:这个答案是只是一种形式,这样回答可以被标记问题

Note: This answer is just a formality, so the question can be marked as answered

这篇关于异步PartialView导致&QUOT; HttpServerUtility.Execute受阻...&QUOT;例外的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆