I have to get checked checkboxes from table column. I have done this to achieve the require result but couldn't find the exact solution and return null value in http post.
public ActionResult Index()
{
return View(db.Users.ToList());
}
[HttpPost]
public ActionResult Index( List<User> user)
{
return View(db.Users.ToList());
}
View
@model IEnumerable<EntityframeworkDemo.User>
@using (Html.BeginForm())
{
<table class="table">
@foreach (var item in Model) {
<tr>
<td>@Html.DisplayFor(modelItem => item.Name)</td>
<td>@Html.DisplayFor(modelItem => item.Phone)</td>
<td>@Html.DisplayFor(modelItem => item.Email)</td>
<td>@Html.DisplayFor(modelItem => item.C_Password)</td>
<td>@Html.CheckBoxFor(modelItem => item.Validations.Value)</td>
</tr> }
</table>
<input type="submit" value="Post" />
}
Model Class:
Class User
{
public int U_id { get; set; }
public string Name { get; set; }
public string Phone { get; set; }
public string Email { get; set; }
public string C_Password { get; set; }
public bool? Validations { get; set; }
}