title: ASP.Net MVC2 Custom Templates Loading via Ajax and Model Updating
body: <p>I have a view model with a collection of other objects in it.</p>
  
  <pre><code>public ParentViewModel
  {
      public int Id { get; set; }
      public string Name { get; set; }
      public List&lt;ChildViewModel&gt; Child { get; set; } 
  }
  
  public ChildViewModel
  {
      public int Id { get; set; }
      public string FirstName { get; set; }
  }
  </code></pre>
  
  <p>In one of my views I pass in a ParentViewModel as the model, and then use</p>
  
  <pre><code>&lt;%: Html.EditorFor(x =&gt; x) %&gt;
  </code></pre>
  
  <p>Which display a form for the Id and Name properties.</p>
  
  <p>When the user clicks a button I call an action via Ajax to load in a partial view which takes a collection of Child:</p>
  
  <pre><code>&lt;%@ Control Language="C#" Inherits="System.Web.Mvc.ViewUserControl&lt;IEnumerable&lt;Child&gt;&gt;" %&gt;
  &lt;%: Html.EditorFor(x =&gt; x) %&gt;
  </code></pre>
  
  <p>which then uses the custom template Child to display a form for each Child passed in.</p>
  
  <p>The problem I'm having is that the form created by the Child custom template does not use the naming conventions used by the DefaultModelBinder.</p>
  
  <p>ie the field name is (when loaded by Ajax):</p>
  
  <pre><code>[0].FirstName
  </code></pre>
  
  <p>instead of:</p>
  
  <pre><code>Child[0].FirstName
  </code></pre>
  
  <p>So the Edit action in my controller:</p>
  
  <pre><code>[HttpPost]
  public virtual ActionResult Edit(int id, FormCollection formValues)
  {
      ParentViewModel parent = new ParentViewModel();
      UpdateModel(parent);
  
      return View(parent);
  }
  </code></pre>
  
  <p>to recreate a ParentViewModel from the submitted form does not work. </p>
  
  <p>I'm wondering what the best way to accomplish loading in Custom Templates via Ajax and then being able to use UpdateModel is.</p>