简体   繁体   English

.Net异步调用局部视图

[英].Net asynchronously calling a partial view

I am hitting a bit of a bug when I am trying to render a partial view that basically displays some slides in a slidereel. 当我尝试渲染基本上在幻灯片放映机中显示一些幻灯片的局部视图时,我遇到了一个错误。

The slides are stored in the db and I know from debugging that my controller method is definitely getting an array of slide objects. 幻灯片存储在db中,从调试中我知道我的控制器方法肯定是要获取一组幻灯片对象。

But it is still throwing this error and I am not sure why. 但是它仍然抛出此错误,我不确定为什么。 The error I am getting is: 我得到的错误是:

{"Error executing child request for handler 'System.Web.Mvc.HttpHandlerUtil+ServerExecuteHttpHandlerAsyncWrapper'."} with the inner exception of: {“执行处理程序'System.Web.Mvc.HttpHandlerUtil + ServerExecuteHttpHandlerAsyncWrapper'的子请求出错。”}内部例外:

HttpServerUtility.Execute blocked while waiting for an asynchronous operation to complete. HttpServerUtility.Execute在等待异步操作完成时被阻止。

I am assuming it is something to do with synchronization, but I am not sure what. 我假设这与同步有关,但是我不确定。

Any help would be greatly appreciated. 任何帮助将不胜感激。

Parent View (index) 父视图(索引)

@{
    ViewBag.Title = "Title";
    Layout = "~/Views/Shared/_Layout.cshtml";

    ViewBag.IsIndex = true;
}

<!-- BEGIN .featured-slider -->
<div class="featured-slider">
    <!-- BEGIN .slider-background -->
    <div class="slider-background">
        <!-- BEGIN .row -->
        <div class="row">
            <!-- BEGIN .sixteen columns -->
            <div class="sixteen columns">
                @{
                    Html.RenderAction("Slideshow", new { controller = "home" });
                }
             <!-- END .sixteen columns -->
            </div>
        <!-- END .row -->
        </div>
    <!-- END .slider-background -->
    </div>
<!-- END .featured-slider -->
</div>

Controller method: 控制器方式:

    public async Task<PartialViewResult> Slideshow()
    {
        var slides = await _slides.GetPublishedSlidesAsync();

        return PartialView("_Slideshow", slides);
    }

_Slideshow partial view: _Slideshow部分视图:

 @model IEnumerable<Models.Slide>

<!-- BEGIN .slideshow -->
<div class="slideshow radius-full">
    <!-- BEGIN .flexslider -->
    <div class="flexslider radius-full" control-nav="true" data-speed="10000" data-transition="slide">
        <!-- BEGIN .slides -->
        <ul class="slides">
            @foreach (var slide in Model)
            {
                <li>
                    <!-- BEGIN .sixteen columns -->
                    <div class="sixteen columns">
                        if(false)
                        { 
                            <div class="feature-vid">

                            </div>
                        }
                        else if (true)
                        {
                            <a class="feature-img radius-full" href="" rel="bookmark" title="">
                                <img src="@slide.Image" />
                            </a>
                            if (false)
                            {
                                <!-- BEGIN .information -->
                                <div class="information radius-full">
                                    <div class="six columns">
                                        <h2 class="headline small">qqqq</h2>
                                    </div>
                                    <div class="ten columns">
                                        <div class="excerpt">aaaa</div>
                                    </div>
                                <!-- END .information -->
                                </div>
                            }
                        }
                    <!-- END .sixteen columns -->
                    </div>
                </li>
            }
        <!-- END .slides -->
        </ul>
    <!-- END .flexslider -->
    </div>
<!-- END .slideshow -->
</div>

Unfortunately, ASP.NET MVC does not support asynchronous partial views on ASP.NET 4.x. 不幸的是,ASP.NET MVC不支持ASP.NET 4.x上的异步局部视图。 This limitation has already been addressed in ASP.NET 5.0 (view components can be asynchronous), but it is unlikely that the 4.x branch will ever support this. 在ASP.NET 5.0中已经解决了此限制(视图组件可以是异步的),但是4.x分支不太可能支持此限制。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM