I did a small prototype for you, Check it out -
Let your models be as shown below. For simplicity sake I ignored some properties.
public class AdminViewModel
{
public List<User> UserList { get; set; }
}
public class User
{
public int Id { get; set; }
public string FirstName { get; set; }
public bool IsAdmin { get; set; }
}
Then the controller action which will render the View -
public ActionResult Index()
{
AdminViewModel model = new AdminViewModel();
model.UserList = new List<User>();
model.UserList.Add(new User() { FirstName = "Rami", IsAdmin = true, Id = 10 });
model.UserList.Add(new User() { FirstName = "James", IsAdmin = false, Id = 20 });
return View(model);
}
Then your view should be as shown below. I used hiddenFields to persist some text properties.
@model MVC.Controllers.AdminViewModel
@{
ViewBag.Title = "Index";
}
<h2>Index</h2>
@using (Html.BeginForm("Submit", "Person", FormMethod.Post))
{
<table>
@for (int i = 0; i < Model.UserList.Count; i++)
{
<tr>
<td>
@Html.DisplayFor(modelItem => Model.UserList[i].Id)
@Html.HiddenFor(modelItem => Model.UserList[i].Id)
</td>
<td>
@Html.DisplayFor(modelItem => Model.UserList[i].FirstName)
@Html.HiddenFor(modelItem => Model.UserList[i].FirstName)
</td>
<td>
@Html.CheckBoxFor(modelItem => Model.UserList[i].IsAdmin)
</td>
</tr>
}
</table>
<input type="submit" value="Save" />
}
When submit button is clicked it will hit the following controller action -
public ActionResult Submit(AdminViewModel model)
{
return View();
}
And when you put a breakpoint, you can see you persisted model as below -