How to render a partial view asynchronously

前端 未结 2 771
刺人心
刺人心 2021-02-01 16:11

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 _La

相关标签:
2条回答
  • 2021-02-01 16:47

    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.

    0 讨论(0)
  • 2021-02-01 17:05

    First of all you need to use Html.Partial as suggested by @buffjape. If your partial view is not in Shared folder you need to specify the path to the view

    @Html.Partial("~/Views/Common/FooterLatestBlogPosts", yourModel)

    However in this case your view is still loaded synchronously. To load it in async way you need to load it via jQuery. Article Improve perceived performance of ASP.NET MVC websites with asynchronous partial views gives a very good description on how to achieve it.

    Also replace your Html.Render with

    $(document).ready(function(){
         $("#yourContainer").load('@Url.Action("FooterLatestBlogPosts", "Common")')
    });
    
    0 讨论(0)
提交回复
热议问题