在以下问题上搜索了很多内容之后。最后决定与你分享。 我有一个模型。查看到控制器MVC的POST列表集合4
public class EarlyBirdWeb
{
public string Client { get; set; }
[Display(Name = "Job Name")]
public string JobName { get; set; }
public List<SelectListItem> Reasons { get; set; }
public List<Status> status { get; set; }
public List<ETA> etas { get; set; }
[Display(Name="Call BU")]
public string CallBU { get; set; }
}
我将此模型绑定到MVC视图。我的观点如下。
@model List<EarlyBird.Models.EarlyBirdWeb>
<form method="post">
@Html.AntiForgeryToken()
<div class="row">
<table class="table table-bordered table-inverse">
<tr class="bg-warning">
<th>Client
</th>
<th>Job Name
</th>
<th>Reason</th>
<th>Status</th>
<th>ETA</th>
<th>CallBU?
</th>
</tr>
@foreach (var item in Model)
{
<tr>
<td>
@item.Client
@Html.Hidden(@item.Client)
</td>
<td>
@item.JobName
</td>
<td>
@Html.DropDownList("--Select One--", (IEnumerable<SelectListItem>)@item.Reasons)
</td>
<td>
<select>
@foreach (var status in item.status)
{
<option value="@status.StatusName">@status.StatusName</option>
}
</select>
</td>
<td>
<select>
@foreach (var etas in item.etas)
{
<option value="@etas.ETATime">@etas.ETATime</option>
}
</select>
</td>
<td>
@item.CallBU
</td>
</tr>
}
</table>
</div>
<div class="row">
<input type="submit" value="Submit" name="Submit" class="btn btn-warning" />
</div>
</form>
现在,当我在视图中填写所有细节并单击提交按钮时,我在控制器中得到空值。
所以,请帮助我如何让我的控制器上的修改列表集合。
谢谢..
可能[将HTML表格复制到ADO.NET DataTable](http://stackoverflow.com/questions/30094047/post-an-html-table-to-ado-net-datatable) –
您不能使用'foreach'循环来生成收集iteme的表单控件(请参阅这个笨蛋) –