My IEnumberable is a null parameter in my action. The binding does not work anymore since I did this:
BEFORE my refactoring
The ListItem.cshtml was inside the List.html
<table id="TeststepsDataTable">
<tbody>
@for (int i = 0; i < Model.Count(); i++)
{
<tr>
@Html.HiddenFor(item => item[i].UnitId)
<td>
@Html.EditorFor(item => item[i].Name)
</td>
</tr>
}
</tbody>
</table>
AFTER my refactoring
List.cshtml
<table id="TeststepsDataTable">
<tbody>
@for (int i = 0; i < Model.Count(); i++)
{
Html.RenderPartial("ListItem", Model[i]);
}
</tbody>
</table>
ListItem.cshtml
@model ITMS.Web.Models.Teststep.TeststepViewModel
<tr>
@Html.HiddenFor(item => Model.UnitId)
<td>
@Html.EditorFor(item => Model.Name)
</td>
</tr>
When my save button in the List.cshtml is clicked this action is triggered:
[HttpPost]
public ActionResult Save(IEnumerable<TeststepViewModel> teststepViewModels)
{
// do stuff
}
The teststepViewModels are null because I lost index property stuff like [0].UnitId so the modelbinder can NOT correctly bind the properties.
How can I fix that?
I really want to use the ListItem.cshtml because I want to reuse this code for an Insert/Add operation an empty row.