如何调用多个局部视图及其视图模型- ASP .NETMVC

3bygqnnd  于 2023-01-14  发布在  .NET
关注(0)|答案(1)|浏览(153)

我有一个名为Register的视图,我在其中使用@Html.Partial(“ViewName”)调用其他视图。我想知道如何从视图中的局部视图调用其他ViewModel。
我知道每个视图模型及其字段都可以在顶部声明,但是我想知道是否有更好的方法可以做?
视图

@model ViewModels.Account.RegisterVM 

<div class="accordion" id="acdRegistration">
    <div class="accordion-item">
        <h2 class="accordion-header" id="headClient">
            <button class="accordion-button" type="button" data-bs-toggle="collapse" data-bs-target="#colClient" aria-expanded="true" aria-controls="colClient">
                Client Registration
            </button>
        </h2>
        <div id="colClient" class="accordion-collapse collapse show" aria-labelledby="headClient" data-bs-parent="#acdRegistration">
            <div class="accordion-body">
                @Html.Partial("_RegisterClient")
--> Here I should call ClientRegistrationVM 
            </div>
        </div>
    </div>
    <div class="accordion-item">
        <h2 class="accordion-header" id="headClinic">
            <button class="accordion-button collapsed" type="button" data-bs-toggle="collapse" data-bs-target="#colClinic" aria-expanded="false" aria-controls="colClinic">
                Clinic Registration
            </button>
        </h2>
        <div id="colClinic" class="accordion-collapse collapse" aria-labelledby="headClinic" data-bs-parent="#acdRegistration">
            <div class="accordion-body">
                @Html.Partial("_RegisterClinic")
--> Here I should call ClinicRegistrationVM 

            </div>
        </div>
    </div>
    <div class="accordion-item">
        <h2 class="accordion-header" id="headRdvm">
            <button class="accordion-button collapsed" type="button" data-bs-toggle="collapse" data-bs-target="#colRdvm" aria-expanded="false" aria-controls="colRdvm">
                RDVM Registration
            </button>
        </h2>
        <div id="colRdvm" class="accordion-collapse collapse" aria-labelledby="headRdvm" data-bs-parent="#acdRegistration">
            <div class="accordion-body">
                @Html.Partial("_RegisterUser")
--> Here I should call UserRegistrationVM 

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

视图模型
一个一个一个一个一个x一个一个二个一个x一个一个三个一个x一个一个x一个四个一个

o3imoua4

o3imoua41#

HtmlHelper.Partial有一个重载版本,它接收一个模型对象,该对象将被传递给局部视图。

Html.Partial("PartialViewName", ModelObject)

相关问题