I'd like to return a list of Personnes from checked checkbox in my view and get it in my controller but selectedObjects count is always 0...
Here's my view with checkboxes:
<tbody>
<tr>
<td>
@foreach (var p in Model.Personnes)
{
<ul>
<li>
@Html.DisplayFor(model => p.NomPersonne) @Html.DisplayFor(model => p.PrenomPersonne)
</li>
</ul>
}
</td>
<td>
@using (Html.BeginForm("Presence", "Evenement"))
{
foreach (var p in Model.Personnes)
{
<ul><input type="checkbox" name="selectedObjects" value="@p" /></ul>
}
@Html.AntiForgeryToken()
<input type="submit" value="Valider Presence" class="btn btn-primary" />
}
</td>
</tr>
@*<tr class="form-group">
<td class="col-md-offset-2 col-md-10" align="right">
<input type="submit" value="Valider Presence" class="btn btn-primary" />
</td>
</tr>*@
</tbody>
my controller:
[HttpPost]
[ValidateAntiForgeryToken]
public ActionResult Presence(List<Personne> selectedObjects)
{
return View(selectedObjects);
}
Aucun commentaire:
Enregistrer un commentaire