这是我的视图模型,其中包含列表访问者
public class CreatePreVisitors
{
public List<Hosts> hosts = new List<Hosts>();
public List<PreVisitors> visitorList = new List<PreVisitors>();
public PreVisitors visitor = new PreVisitors();
}
这是我使用模型创建访问者的视图,在此模型中,我已经从后端填充了主机。我想要做的是填写并返回通过文本框填充在我的视图中的访问者列表,或者返回创建访问者viewmodel并填充我的访问者列表
@model BLL.ViewModels.CreatePreVisitors
<h2>AddPreVisitor</h2>
<div class="row">
<div class="form-group col-md-12">
<h5 style="font-weight: bold;">Register User</h5>
@using (Html.BeginForm("addMultipleVisitor", "PreVisitor", FormMethod.Post, new { id = "Visitor-form" }))
{
@Html.AntiForgeryToken()
@Html.ValidationSummary()
<div><a href="#" id="addNew">Add New</a></div>
<div class="table-responsive">
<table class="table table-bordered" id="dataTable">
<tr >
<th>NIC</th>
<th>First Name</th>
<th>Last Name</th>
<th>Address</th>
<th>Company</th>
<th>Contact No</th>
<th>Host</th>
<th>Host Email</th>
<th>From Date</th>
<th>to Date</th>
<th>Time</th>
@*<th></th>*@
</tr>
@if (Model.visitorList != null && Model.visitorList.Count > 0)
{
int j = 0;
foreach (var i in Model.visitorList)
{
<tr style="border:1px solid" >
<td>@Html.TextBoxFor(a =>Model.visitorList[j].VNIC, new {@class=" form-control"}) </td>
<td>@Html.TextBoxFor(a => Model.visitorList[j].VfirstName, new { @class = " form-control" })</td>
<td>@Html.TextBoxFor(a => Model.visitorList[j].VlastName, new { @class = " form-control" })</td>
<td>@Html.TextBoxFor(a => Model.visitorList[j].Vaddress, new { @class = " form-control" })</td>
<td>@Html.TextBoxFor(a => Model.visitorList[j].Vcompany, new { @class = " form-control" })</td>
<td>@Html.TextBoxFor(a => Model.visitorList[j].VphoneNo, new { @class = " form-control" })</td>
<td>@Html.DropDownListFor(a => Model.visitorList[j].host_id, new SelectList(Model.hosts, "EmpID", "hFirst", 0), new {@class="form-control"})</td>
<td>@Html.TextBoxFor(a => Model.visitorList[j].host_email, new { @class = " form-control" })</td>
<td>@Html.TextBoxFor(a => Model.visitorList[j].from_Date, new { @class = "datepicker form-control" })</td>
<td>@Html.TextBoxFor(a => Model.visitorList[j].to_date, new { @class = "datepicker form-control" })</td>
<td>@Html.TextBoxFor(a => Model.visitorList[j].Time, new { @class = "timepicker form-control" })</td>
@*<td>
@if (j > 0)
{
<a href="#" class="remove">Remove</a>
}
</td>*@
</tr>
j++;
}
}
</table>
</div>
<input type="submit" id="vv" value="Save Bulk Data" />
}
</div>
这是我的控制器,它提交,我想要访问者列表。任何人都可以帮助我,我该怎么办?
[HttpPost]
public ActionResult addMultipleVisitor(List<BLL.ViewModels.PreVisitors> PreVisitors)
{
BLL.PreVisitors.addMultipleVisitor(PreVisitors);
return RedirectToAction("addMultipleVisitor");
}