Blind guess:
change:
<%= Html.TextBox("Complainants[" + i + "].Surname", complainant.Surname)%>
with:
<%= Html.TextBox("Complaint.Complainants[" + i + "].Surname",
complainant.Surname)%>
Respectively - add "Complaint." before "Complainants[..."
EDIT:
This is NOT a right answer. Left it undeleted just because that might add some value until proper answer pops up.
EDIT2:
I might be wrong, but for me it seems there's problem with entity framework (or - with the way you use it). I mean - asp.net mvc manages to read values from request but can't initialize complainants collection.
Here it's written:
The InitializeRelatedCollection(TTargetEntity) method initializes an existing EntityCollection(TEntity) that was created by using the default constructor. The EntityCollection(TEntity) is initialized by using the provided relationship and target role names.
The InitializeRelatedCollection(TTargetEntity) method is used during deserialization only.
Some more info:
Exception:
- InvalidOperationException
Conditions:
- When the provided EntityCollection(TEntity) is already initialized.
- When the relationship manager is already attached to an ObjectContext.
- When the relationship manager already contains a relationship with this name and target role.
Somewhy InitializeRelatedCollection gets fired twice. Unluckily - i got no bright ideas why exactly. Maybe this little investigation will help for someone else - more experienced with EF. :)
EDIT3:
This isn't a solution for this particular problem, more like a workaround, a proper way to handle model part of mvc.
Create a viewmodel for presentation purposes only. Create a new domain model from pure POCOs too (because EF will support them in next version only). Use AutoMapper to map EFDataContext<=>Model<=>ViewModel.
That would take some effort, but that's how it should be handled. This approach removes presentation responsibility from your model, cleans your domain model (removes EF stuff from your model) and would solve your problem with binding.