title: Model binding with nested child models and PartialViews in ASP.NET MVC
body: <p>I have the following types and classes:</p>
  
  <pre><code>namespace MVC.Models
  
  public class Page 
  {
     public EditableContent Content {get; set; }
  }
  
  public class EditableContent
  {
      public TemplateSection SidebarLeft {get; set; }
      public TemplateSection SidebarRight {get; set; }
  }
  </code></pre>
  
  <p>I want to edit the <code>Page</code> instance in my <code>Edit.aspx</code> View. Because <code>EditableContent</code> is also attached to other models, I have a <code>PartialView</code> called <code>ContentEditor.ascx</code> that is strongly typed and takes an instance of <code>EditableContent</code> and renders it.</p>
  
  <p>The rendering part all works fine, but when I post - everything inside my <code>ContentEditor</code> is not binded - which means that <code>Page.Content</code> is <code>null</code>.</p>
  
  <p>On the PartialView, I use strongly typed Html Helpers to do this:</p>
  
  <pre><code>&lt;%= Html.HiddenFor(m =&gt; m.TemplateId) %&gt;
  </code></pre>
  
  <p>But because the input elements on the form that are rendered by <code>ContentEditor.ascx</code> does not get the <code>Content</code> prefix to its <code>id</code> attribute - the values are not binded to <code>Page</code>.</p>
  
  <p>I tried using loosely typed helpers to overcome this:</p>
  
  <pre><code>&lt;%= Html.Hidden("Content.TemplateId", Model.TemplateId) %&gt;
  </code></pre>
  
  <p>And when I'm dealing with a property that is a <code>List&lt;T&gt;</code> of something it gets very ugly. I then have to render collection indexes manually.</p>
  
  <p>Should I put both Page and EditableContent as parameters to the controller action?:</p>
  
  <pre><code>public ActionResult Edit(Page page, EditableContent content) { ... }
  </code></pre>
  
  <p>What am I missing?</p>