List<T>
can be tricky when modelbinding since it relies heavily on the indexed keys. The helpers need to know the index, but by assigning notif
within your for loop they're losing the reference. Instead, try something like the following:
@for (int i = 0; i < Model.ListNotification.Count(); i++ )
{
var notif = Model.ListNotification[i];
<tr>
<td>@notif.GroupDesc </td>
<td>Heure de notification</td>
<td>@Html.CheckBoxFor(u => u.ListNotification[i].AM) </td>
<td>@Html.CheckBoxFor(u => u.ListNotification[i].PM) </td>
<td>@Html.TextBoxFor(u => u.ListNotification[i].MaxNotif)</td>
</tr>
<tr/>
}
Which should then provide you with something like:
<tr>
<td>Groupe B </td>
<td>Heure de notification</td>
<td>
<input id="ListNotification[0]_AM" name="ListNotification[0].AM" type="checkbox" value="true" />
<input name="ListNotification[0].AM" type="hidden" value="false" />
</td>
<td>
<input checked="checked" id="ListNotification[0]_PM" name="ListNotification[0].PM" type="checkbox" value="true" />
<input name="ListNotification[0].PM" type="hidden" value="false" />
</td>
<td>
<input id="ListNotification[0]_MaxNotif" name="ListNotification[0].MaxNotif" type="text" value="10" />
</td>
</tr>
Also, make sure to check ModelState.IsValid
in your posted action to confirm the model was bound correctly. If not, you should see a list of errors in ModelState
that would give you some indication as to where it may have failed.
Also, I don't see you dump GroupDesc
anywhere (except to output). If this is necessary on the incoming model, you may consider using @Html.HiddenFor(x => x.ListNotifications[i].GroupDesc)
.