I have a view model which gets displayed in a cshtml view like this:
@model MyViewModel
<form action="...">
@foreach (var item in this.Model.MyList)
{
<input type="checkbox" name="item.Name"/>
}
</form>
Then I have a controller method on the backend:
[HttpPost]
public ActionResult SaveMyViewModel(MyViewModel viewModel)
{
...
When I inspect the viewModel
in the controller method while POSTing, it has all null properties. I would expect it to have values in MyList
and in there, bools for each item in MyList
.
Is this possible without Ajax? I cannot use ajax here.
What must be done to the form in order to properly return an accurate representation of the viewModel back to the server?