简体   繁体   中英

.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.

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:

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

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:

 @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. 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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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