In an ASP.NET MVC application, the model is a list of objects. It is used in the view like this:
<h4>Order Acknowledgement Contact(s)</h4>
@foreach (var contact in Model.Where(c => c.Type == "AK").Take(3))
{
<div class="form-group">
<div class="col-md-10">
@Html.EditorFor(c => contact.Email, new { htmlAttributes = new { @class = "form-control" } })
@Html.ValidationMessageFor(c => contact.Email, "", new { @class = "text-danger" })
</div>
</div>
}
<h4>Shipping Acknowledgement Contact(s)</h4>
@foreach (var contact in Model.Where(c => c.Type == "BK").Take(3))
{
<div class="form-group">
<div class="col-md-10">
@Html.EditorFor(c => contact.Email, new { htmlAttributes = new { @class = "form-control" } })
@Html.ValidationMessageFor(c => contact.Email, "", new { @class = "text-danger" })
</div>
</div>
}
When the form is submitted, in the controller the List is null.
[HttpPost]
public ActionResult Edit(List<CustomerContact> customerContacts)
{
Is it possible to fix binding and preserve using linq etc?