Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>Blind guess: </p> <p>change:</p> <pre><code>&lt;%= Html.TextBox("Complainants[" + i + "].Surname", complainant.Surname)%&gt; </code></pre> <p>with:</p> <pre><code>&lt;%= Html.TextBox("Complaint.Complainants[" + i + "].Surname", complainant.Surname)%&gt; </code></pre> <p>Respectively - add "Complaint." before "Complainants[..."</p> <p><strong>EDIT</strong>:</p> <p>This is NOT a right answer. Left it undeleted just because that might add some value until proper answer pops up.</p> <p><strong>EDIT2:</strong></p> <p>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. </p> <p><a href="http://msdn.microsoft.com/en-us/library/cc679591.aspx" rel="nofollow noreferrer">Here</a> it's written: </p> <blockquote> <p>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.</p> <p>The InitializeRelatedCollection(TTargetEntity) method is used during deserialization only.</p> </blockquote> <p>Some more info: </p> <blockquote> <p>Exception:</p> <ul> <li>InvalidOperationException </li> </ul> <p>Conditions: </p> <ul> <li>When the provided EntityCollection(TEntity) is already initialized. </li> <li>When the relationship manager is already attached to an ObjectContext. </li> <li>When the relationship manager already contains a relationship with this name and target role. </li> </ul> </blockquote> <p>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. :) </p> <p><strong>EDIT3:</strong><br> This isn't a solution for this particular problem, more like a workaround, a proper way to handle model part of mvc. </p> <p>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 <a href="http://automapper.codeplex.com/" rel="nofollow noreferrer">AutoMapper</a> to map EFDataContext&lt;=>Model&lt;=>ViewModel. </p> <p>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.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload