title: ASP.NET Model binder question for updating child table
body: <p>I'm using Linq to SQL within an ASP.NET MVC application. The model consists of a Decisions table with a foreign key link to an Options table (one decision, many options).  So the Model allows me to access the Options collection through the Decision.Options property.  I want to allow my users to update the Options collection for a Decision in a separate view from updating other Decision properties.  What is the best way to pass the Options collection back into the controller in order to update the Decision object?  Here's the code:</p>
  
  <p>The controller sends a Decision model to the Options view:</p>
  
  <pre><code>   //
      // GET /Decisions/Options/5
       [Authorize]
       public ActionResult Options(int id)
       {
           Decision decision = decisionRepository.GetDecision(id);
           return View(decision);
       }
  </code></pre>
  
  <p>My view page just lists the Option's Name field for users to modify and submit:</p>
  
  <pre><code>&lt;% using (Html.BeginForm())
  {%&gt;
      &lt;div id="answers"&gt;
          &lt;table&gt;
          &lt;% int i = 0; %&gt;  
          &lt;% foreach (var item in Model.Options)
             { i += 1;
           %&gt;
              &lt;tr&gt;
                  &lt;td&gt;
                      &lt;label&gt;Option #&lt;%= i%&gt;:&amp;nbsp;&amp;nbsp;&lt;/label&gt;
                      &lt;%= Html.TextBox("Option.Name", item.Name)%&gt;
                  &lt;/td&gt;
              &lt;/tr&gt;
  
          &lt;% } %&gt;
          &lt;/table&gt;
  
          &lt;input type="submit" name="button" value="Back" /&gt;
          &lt;input type="submit" name="button" value="Next" /&gt;
      &lt;/div&gt;
      &lt;% } %&gt;
  </code></pre>
  
  <p>Here is the controller code for the Options POST action:</p>
  
  <pre><code>     // POST /Decisions/Options/4
       [AcceptVerbs(HttpVerbs.Post), Authorize]
       public ActionResult Options(int id, string button, Decision d)
       {
           Decision decision = decisionRepository.GetDecision(id);
  
           if (decision == null)
               return View("NotFound");
  
           if (button == "Back")
           {
               return RedirectToAction("Edit", new { id = decision.DecisionID });
           }
  
           //Update the options in the decision model             
           //TODO: What's the best way to update the Decision.Options parameter?
  
           //Save options and move on to factors
           UpdateModel(decision);
           decisionRepository.Save();
           return RedirectToAction("Factors", new { id = decision.DecisionID });
       }
  </code></pre>
  
  <p>On the POST action for Options, what is the best way to pass back the collection of Option items?  </p>
  
  <p>I've tried working with the FormCollection directly to convert to an EntitySet for assignment to Decision.Options before calling the Save method.  The code above has the Decision object being passed in, but the Options collection is always null, hence my commented TODO.</p>
  
  <p>I've gotten this to work for editing the Decision object directly, but am having problems with updating a child table in the model using a Model Binder or FormCollection.  Any help is greatly appreciated!</p>