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 リストの項目を反復処理しようとしています。これが理にかなっていることを願っています。
ありがとう