title: MVC3 - Viewmodel with list of complex types
body: <p>Apologies if this has been asked before; there are a million ways to phrase it so searching for an answer has proved difficult.</p>
  
  <p>I have a viewmodel with the following properties:</p>
  
  <pre><code>public class AssignSoftwareLicenseViewModel
  {
      public int LicenseId { get; set; }
      public ICollection&lt;SelectableDeviceViewModel&gt; Devices { get; set; }
  }
  </code></pre>
  
  <p>A simplified version of SelectableDeviceViewModel would be this:</p>
  
  <pre><code>public class SelectableDeviceViewModel
  {
      public int DeviceInstanceId { get; set; }
      public bool IsSelected { get; set; }
      public string Name { get; set; }
  }
  </code></pre>
  
  <p>In my View, I am attempting to display a list of editable checkboxes for the Devices property, inside an input form.
  Currently, my View looks like this:</p>
  
  <pre><code>@using (Html.BeginForm())
  {
      @Html.HiddenFor(x =&gt; Model.LicenseId)
      &lt;table&gt;
          &lt;tr&gt;
              &lt;th&gt;Name&lt;/th&gt;
              &lt;th&gt;&lt;/th&gt;
          &lt;/tr&gt;
          @foreach (SelectableDeviceViewModel device in Model.Devices)
          {
              @Html.HiddenFor(x =&gt; device.DeviceInstanceId)
              &lt;tr&gt;
                  &lt;td&gt;@Html.CheckBoxFor(x =&gt; device.IsSelected)&lt;/td&gt;
                  &lt;td&gt;@device.Name&lt;/td&gt;
              &lt;/tr&gt;
          }
      &lt;/table&gt;
  
      &lt;input type="submit" value="Assign" /&gt;
  }
  </code></pre>
  
  <p>The problem is, when the model gets posted back to the controller, Devices is null.</p>
  
  <p>My assumption is that this is happening because even though I'm editing its contents, the Devices property is never explicitly included in the form. I tried including it with HiddenFor, but that just resulted in the model having an empty list instead of null.</p>
  
  <p>Any idea what I'm doing wrong here?</p>