Suppose I have passed in a viewmodel with a PERSON record with multiple addresses
I'm looking to write a view something like this (simplified)
<% foreach (var addr in Model.PERSON.ADDRESSES) { %>
<li>
<%: Html.TextBoxFor(m => addr.Add1)%>
</li>
<% } %>
Which appears to display as expected, however, each generated Textbox has the same ID and Name attributes, and not surprisingly, the controller code fails to make any updates to the model.
[HttpPost]
public ActionResult Edit(int id, FormCollection collection)
{
MyViewModel viewmodel = GenerateViewModel(id);
try
{
UpdateModel(viewmodel);
_MyRepository.Save();
return View(viewmodel);
}
catch
{
return View(viewmodel);
}
}
I'm guessing I'm going about this the wrong way: any clues would be greatly appreciated!