【问题标题】:Loading multiple viewcomponents in an ASP.net core 2.2 cshtml在 ASP.net core 2.2 cshtml 中加载多个视图组件
【发布时间】:2020-04-02 08:40:56
【问题描述】:

我是 Asp.Net core 的新手,但我使用过 Asp.net MVC 5。我在一个视图中加载多个视图组件时遇到问题。(使用 Asp.net core 2.2) 我的页面在其中加载了viewcomponent。 这是我的页面:

    <div id="frmSoftPhone_pageUniqueId">
            <div id="sipClient" class="custom-tab">
                <ul>       

                     <li class="active"
                            data-init="init"
                            data-parentObj="cc.pageDesktop"><i class="icon-desktop"></i></li>
                </ul>
               <div id="desktop-container" class="active" style="height: 650px">
                        @await  Component.InvokeAsync("TestViewComponent")
                    </div>
            </div>
        </div>

然后在我的“TestViewComponent”中,我也加载了一些viewcomponents。 我的 TestViewComponent 是这个

    @{
        Layout = null;
    }

    <div class="container">
        <div class="container-item">
            <div class="custom-tab">
                <ul>
                    <li class="active session-content-li"><i class="fa fa-file-text"></i></li>
                    <li><i class="fa fa-users"></i></li>
                    <li style="position: relative">
                        <span id="v-call-count" style="display: none">0</span><span class="icon-queue"></span>
                    </li>
                    <li style="position: relative">
                        <span id="p-call-count" style="display: none">0</span><span class="icon-p-queue"></span>
                    </li>
                </ul>
                <div class="active session-content">
                    @await Component.InvokeAsync("GroupEmail", new GroupEmailModel())
                    @await Component.InvokeAsync("CallHistory")
                    @await Component.InvokeAsync("SmsContainer")
                </div>
                <div>
                    <div class="tabcontent">
                        @await Component.InvokeAsync("OnlineAgentstatus")
                    </div>
                </div>
                <div>
                    <div class="tabcontent">
                        @await Component.InvokeAsync("VCallsContainer")
                    </div>
                </div>
                <div>
                    <div class="tabcontent">
                        @await Component.InvokeAsync("PCallsContainer")
                    </div>
                </div>

            </div>
        </div>
    </div>

我的viewcomponents 都没有“异步”代码。通过调试,我看到我所有的viewcomponents 都在通过跟踪加载,但最后当一切都完成时,只有第一个组件“GroupEmail”。同样在更改加载顺序时viewcomponents,再次只是第一个或有时两个加载在 HTML 中。我也尝试使用 Html.PartialAsync 和 Html.Partial。但同样的结果发生了。 我在这个问题上卡住了 2 天。任何帮助,我将不胜感激。

谢谢

【问题讨论】:

    标签: asp.net-core asp.net-core-mvc asp.net-core-2.0


    【解决方案1】:

    我通过一次又一次的测试发现了一些东西。我在部分视图(全部)中有剑道网格或树列表。删除它们时一切都很好并且它工作正常。如果解决了我正在尝试找到确切的问题我会在这里发布解决方案。

    谢谢

    【讨论】:

      【解决方案2】:

      终于找到了,

      剑道模型在列中绑定错误。所以刚刚纠正了它,所有视图组件现在都可以正常工作了。

      【讨论】:

        猜你喜欢
        • 2021-08-30
        • 1970-01-01
        • 1970-01-01
        • 2019-06-21
        • 1970-01-01
        • 1970-01-01
        • 2021-10-06
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多