【发布时间】:2021-03-19 20:14:01
【问题描述】:
我在 mvc 中要求包含多个员工。所以有一个基本的员工表格,如下所示。
单击“添加员工”按钮应包括下一行的另一部分,以输入其他员工详细信息。
克隆对象将创建该部分的副本。我需要的是,添加/删除将绑定到视图模型列表的多个员工的能力,即在这种情况下
列表
<form method="POST" enctype="multipart/form-data" id="employeeForm" novalidate>
@Html.AntiForgeryToken()
<div class="final-mile__step-employee">
<div class="row">
<div class="col-md-6">
<div class="form-group">
<label for="FirstName">First Name</label>
@Html.TextBoxFor(model => model.FirstName, new { @class = "form-control", required = "required", placeholder = "First Name" })
@Html.ValidationMessageFor(model => model.FirstName, "", new { @class = "text-danger" })
</div>
<div class="form-group">
<label for="LastName">Last Name</label>
@Html.TextBoxFor(model => model.LastName, new { @class = "form-control", required = "required", placeholder = "Last Name" })
@Html.ValidationMessageFor(model => model.LastName, "", new { @class = "text-danger" })
</div>
<div class="form-group">
<label for="Dob">Date Of Birth</label>
@Html.TextBoxFor(model => model.Dob, new { @class = "form-control", required = "required", placeholder = "Date of Birth" })
@Html.ValidationMessageFor(model => model.Dob, "", new { @class = "text-danger" })
</div>
</div>
</div>
<div class="row final-mile__step-control">
<div class="col justify-content-center">
<button id="Add Employee">Add Employee</button>
</div>
</div>
</div>
</form>
任何输入都会有所帮助。
【问题讨论】:
-
我的回答有用吗?如果有用,可以标记为答案吗,谢谢。
-
首先感谢您的输入。关于解决方案,我不能使用 html 附加逻辑,但必须使用克隆选项。不附加 html 的原因是,我正在处理的表单包括不建议使用大约 30-25 个字段并附加 html 标签,因此必须克隆整个 div 部分。
标签: asp.net-core model-view-controller razor