如何将页面内容加载到另一个页面的弹出窗口中?

How can I load page content's onto another page's popup?

这是带有弹出窗口的主页的html代码

<div class="box">
  <a class="button" href="#divOne">
    <img src="~/images/usericon.png" alt="user" width="30" height="30" />
  </a>
</div>

<div class="overlay" id="divOne">
  <div class="wrapper">
    <div id="container">
      <div class="btn" id="btn-1" data-showbutton="1">Login</div>
      <div data-button="1">
        <a href="#" class="close" onclick="clearData()">&times;</a>
        <div class="content">
          <div class="container text-active">
            @* load page content here*@
            <form id="login">
              <label>Username</label>
              <input type="text" placeholder="Username" />

              <label>Password</label>
              <input type="text" placeholder="Password" />
            </form>
          </div>
        </div>
        <button>Login</button>
      </div>

      <div class="btn" id="btn-2" data-showbutton="2">Register</div>
      <div id="is-hidden" data-button="2">
        <a href="#" class="close" onclick="clearData()">&times;</a>
        <div class="content">
          <div class="container">

            <div class="container text-active">
              @* load page content here*@
              <form id="register">
                <label>Username</label>
                <input type="text" placeholder="Username" />

                <label>Password</label>
                <input type="text" placeholder="Password" />

                <label>Confirm Password</label>
                <input type="text" placeholder="Confirm Password" />
              </form>
            </div>
          </div>
        </div>
        <button>Register</button>
      </div>
    </div>
  </div>

</div>

这是我要在弹出窗口中显示的页面内容

 @model Store.Models.CustomerModel

@{
    ViewData["Title"] = "Register";
}
@* this part is what I need*@
<div class="row">
    <div class="col-md-4">
        <form asp-action="Register">
            <div asp-validation-summary="ModelOnly" class="text-danger"></div>
            <div class="form-group">
                <label asp-for="CustomerEmail" class="control-label"></label>
                <input asp-for="CustomerEmail" class="form-control" />
                <span asp-validation-for="CustomerEmail" class="text-danger"></span>
            </div>
            <div class="form-group">
                <label asp-for="CustomerPassword" class="control-label"></label>
                <input asp-for="CustomerPassword" class="form-control" />
                <span asp-validation-for="CustomerPassword" class="text-danger"></span>
            </div>
            <div class="form-group">
                <input type="submit" value="Create" class="btn btn-primary" />
            </div>
        </form>
    </div>
</div>
@* this part is what I need*@

我试过包含模型并粘贴代码并且它有效,但我想在主页与登录和注册表单之间进行分离。

这就是它的样子,如果需要的话

将重复的代码移动到 partial,其 @model 设置为 CustomerModel:

@model CustomerModel
<div class="row">
    <div class="col-md-4">
        <form asp-action="Register">
            <div asp-validation-summary="ModelOnly" class="text-danger"></div>
            <div class="form-group">
                <label asp-for="CustomerEmail" class="control-label"></label>
                <input asp-for="CustomerEmail" class="form-control" />
                <span asp-validation-for="CustomerEmail" class="text-danger"></span>
            </div>
            <div class="form-group">
                <label asp-for="CustomerPassword" class="control-label"></label>
                <input asp-for="CustomerPassword" class="form-control" />
                <span asp-validation-for="CustomerPassword" class="text-danger"></span>
            </div>
            <div class="form-group">
                <input type="submit" value="Create" class="btn btn-primary" />
            </div>
        </form>
    </div>
</div>

在主页中,您需要添加一个CustomerModel 属性 例如

public CustomerModel Customer { get; set; }

然后将其传递给部分,您可以使用 partial tag helper:

 <div class="overlay" id="divOne">
    <div class="wrapper">
        <div id="container">
            <div class="btn" id="btn-1" data-showbutton="1">Login</div>
            <div data-button="1">
                <a href="#" class="close" onclick="clearData()">&times;</a>
                <div class="content">
                    <div class="container text-active">
                        @* load page content here*@
                        <partial name="_RegisterForm" for="Customer" />
                        @* load page content here*@
                    </div>
                </div>
            </div>
            <button>Register</button>
        </div>
    </div>
</div>

在 Customer 页面中,您再次包含了 partial,但是您不需要通过 partial 中的 for 属性指定模型,因为默认情况下将传递主机页面的模型:

@page
@model WebApplication4.Pages.CustomerModel
@{
    ViewData["Title"] = "Register";
}
@* this part is what I need*@
<partial name="_RegisterForm" />
@* this part is what I need*@