我有一个带有 IList 的视图模型:
public class MyMaintenanceListViewModel
{
public IList<MyMaintenance> MyMaintenanceList { get; set; }
[Display(Name = "Network User Name:")]
public string NetworkUserName { get; set; }
[Display(Name = "Password:")]
public string Password { get; set; }
}
我有一个视图,其模型设置为视图模型:
@model EMMS.ViewModels.MyMaintenanceListViewModel
@using (Html.BeginForm("SubmitMaintenance", "Maintenance"))
{
<table id="searchtable" class="MyMaintenance">
<tr>
<th style="width: 50px; text-align: left;">Id</th>
<th style="width: 200px; text-align: left;">Equipment Id</th>
<th style="width: 100px; text-align: left;">Task Id</th>
<th style="width: 150px; text-align: left;">Date Completed</th>
<th style="width: 100px; text-align: left;">Elapsed Time</th>
<th style="width: 200px; text-align: left;">Created</th>
<th style="width: 50px;"></th>
</tr>
@for (int i = 0; i < Model.MyMaintenanceList.Count; i++)
{
var item = Model.MyMaintenanceList[i];
<tr>
<td>
@Html.DisplayFor(modelItem => item.RowId)
@Html.HiddenFor(modelItem => item.RowId)
</td>
<td>
@Html.DisplayFor(modelItem => item.EquipmentId)
</td>
<td>
@Html.DisplayFor(modelItem => item.TaskId)
</td>
<td>
@Html.DisplayFor(modelItem => item.DateCompleted)
</td>
<td>
@Html.DisplayFor(modelItem => item.ElapsedTimeMinutes)
</td>
<td>
@Html.DisplayFor(modelItem => item.CreateDate)
</td>
</tr>
}
</table>
}
我的控制器看起来像这样:
[HttpPost]
public ActionResult SubmitMaintenance(MyMaintenanceListViewModel myMaintenanceListViewModel)
{
// do something with IList "MyMaintenanceList" in myMaintenanceListViewModel
}
但是,当我对上面的控制器 post 方法进行断点并提交表单时,myMaintenanceListViewModel 中的 MyMaintenanceList 列表显示 count=0,即使视图中有项目。如何将此表中的项目传递给控制器中的 post 方法?
我正在尝试遍历控制器中 MyMaintenanceList 列表中的项目。希望这是有道理的。
谢谢