Note that there are some explanatory texts on larger screens.

plurals
  1. POUpdating Parent/Child Records with model binders in ASP.Net MVC
    text
    copied!<p>I have modified the <a href="http://www.nerddinner.com/" rel="nofollow noreferrer">Nerd Dinner</a> application to allow editing of child records by adding the following code to the DinnerForm.ascx</p> <pre><code> &lt;p&gt; &lt;%int i = 0; foreach (NerdDinner.Models.RSVP rsvp in this.Model.Dinner.RSVPs) { %&gt; &lt;%= Html.Hidden("Dinner.RSVPs[" + i + "].RsvpID", rsvp.RsvpID)%&gt; &lt;%= Html.Hidden("Dinner.RSVPs[" + i + "].DinnerID", rsvp.DinnerID)%&gt; &lt;%= Html.TextBox("Dinner.RSVPs[" + i + "].AttendeeName", rsvp.AttendeeName)%&gt; &lt;% i += 1; } %&gt; &lt;/p&gt; </code></pre> <p>it is rendering this:</p> <pre><code>&lt;p&gt; &lt;input id="Dinner_RSVPs[0]_RsvpID" name="Dinner.RSVPs[0].RsvpID" type="hidden" value="36" /&gt; &lt;input id="Dinner_RSVPs[0]_DinnerID" name="Dinner.RSVPs[0].DinnerID" type="hidden" value="63" /&gt; &lt;input id="Dinner_RSVPs[0]_AttendeeName" name="Dinner.RSVPs[0].AttendeeName" type="text" value="kp" /&gt; &lt;input id="Dinner_RSVPs[1]_RsvpID" name="Dinner.RSVPs[1].RsvpID" type="hidden" value="37" /&gt; &lt;input id="Dinner_RSVPs[1]_DinnerID" name="Dinner.RSVPs[1].DinnerID" type="hidden" value="63" /&gt; &lt;input id="Dinner_RSVPs[1]_AttendeeName" name="Dinner.RSVPs[1].AttendeeName" type="text" value="jim" /&gt; &lt;/p&gt; </code></pre> <p>I have not modified the DinnersControler's Post Edit Action method. The Parent dinner is getting updated as usual, but it appears the UpdateModel(dinner); is not seeing/updating the child RSVP records.</p> <p>I have tried a few variations on rendering the child records so that the Model binders will see the collection, with no luck.</p> <p>Is updating parent/child records in one shot by calling UpdateModel(Parent); possible with the current model binders?</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