I have a section of my site where users can add addresses to their account. They may add as many as they need (shipping, billing, etc).
I set things up so that after an address is added, the users sees the address in an update form with a "save" and "delete" button. The user can adjust any of the addresses they have added.
The problem I am having is with validation. Let's say Line 1 is required. If I am updating the second of three addresses and leave Line 1 empty the controller is raising an error (using the same technique from Nerd Dinner, BTW). This is good. What is bad is that all of the address info on all of the addresses listed in the view, now show as values from the address where the error was raised.
I know this has something to do with model binding, but I am confused, as the form data is set up as follows:
<%= Html.TextBox("Line1", Model.Address.Line1)%>
The Model that is passed in is unique to the address we are on in the list of client addresses. I am not sure why the value in "Model.Addres.Line1" is being overridden by data in the ModelState ModelErrors Collection. I guess the default behavior is to use the values from the errors collection when they are present. This is a problem when there is more than one form on the View and the form is using the same Names for input fields as each of the other forms.
Is my only work-around to avoind the Html Helper function here and hard-code the inputs in HTML?