简体   繁体   English

如何在div中异步加载多个局部视图

[英]How to load multiple partial view in div asynchronously

Team, I have a view which contains four partial view, which data is independent hence need to load them asynchronously.团队,我有一个包含四个部分视图的视图,这些数据是独立的,因此需要异步加载它们。 Div are formed as - Div 形成为 -

   <div class="col-md-6 partialContent" data-url="/Dashboard/PartialView1">
   </div>
   <div class="col-md-6 partialContent" data-url="/Dashboard/PartialView2">
   </div>

Controller Actions are.控制器动作是。 (Added thread.speep as wanted to check if it wait or process another method after div.load call) (添加了 thread.speep 以检查它是否在 div.load 调用后等待或处理另一个方法)

public PartialViewResult PartialView1()
    {
        PartialView1ViewModel dcVM = new PartialView1ViewModel();
        // business logic code is here
        Thread.Sleep(5000);
        return PartialView("~/Views/Charts/_PartialView1.cshtml", dcVM);
    }
    public PartialViewResult PartialView2()
    {
        PartialView1ViewModel dcVM = new PartialView1ViewModel();
        // business logic code is here
        return PartialView("~/Views/Charts/_PartialView2.cshtml", dcVM);
    }

And finally, loading data into div as -最后,将数据加载到 div 中 -

    $(".partialContent").each(function (index, item) {

    var url = $(item).data("url");
    if (url && url.length > 0) {
        $(item).load(url);
    }
});

So in this case we are expecting both method should be called, immediately but it waits till first methods processing completes.因此,在这种情况下,我们希望立即调用这两个方法,但它会等到第一个方法处理完成。

How can we load all these partial views asynchronously without waiting for other action complete?我们如何在不等待其他操作完成的情况下异步加载所有这些部分视图?

Can you please hint/guide?你能提示/指导吗?

I guess in your case, server locks requests by session (so session becomes thread safe for writing).我猜在你的情况下,服务器通过会话锁定请求(因此会话成为线程安全的写入)。 If you disable it or make read-only in required actions you can achieve expected result.如果您禁用它或在所需的操作中将其设为只读,则可以达到预期的结果。

Please check link for more details请查看链接了解更多详情

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

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