I have a view model with a 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; }
}
I have a view whose model is set to the viewmodel:
@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>
}
My controller looks something like this:
[HttpPost]
public ActionResult SubmitMaintenance(MyMaintenanceListViewModel myMaintenanceListViewModel)
{
// do something with IList "MyMaintenanceList" in myMaintenanceListViewModel
}
However, when I breakpoint the controller post method above and submit the form, the MyMaintenanceList list in myMaintenanceListViewModel says count=0, even though there are items in the view. How can I pass the items in this table to a post method in my controller?
I am trying to iterate over the items in the MyMaintenanceList list in the controller. Hope this makes sense.
Thanks