title: Model binding postback data to a controller action parameter of type List<T>
body: <p>I have a strong type view of type </p>
  
  <pre><code>List&lt;List&lt;MyViewModelClass&gt;&gt;
  </code></pre>
  
  <p>The outer list will always have two lists of <code>List&lt;MyViewModelClass&gt;</code>. For each of the two outer lists I want to display a group of checkboxes. Each set can have an arbitrary number of choices.</p>
  
  <p>My view model class looks similar to this:</p>
  
  <pre><code>public class MyViewModelClass
  {
      public Area Area { get; set; }
  
      public bool IsGeneric { get; set; }
  
      public string Code { get; set; }
  
      public bool IsChecked { get; set; }
  }
  </code></pre>
  
  <p>So the final view will look something like:</p>
  
  <hr>
  
  <p>Please select those that apply:</p>
  
  <p><strong>First set of choices:</strong></p>
  
  <ul>
  <li><kbd>x</kbd> Option 1</li>
  <li><kbd>x</kbd> Option 2</li>
  <li><kbd>x</kbd> Option 3</li>
  <li>etc.</li>
  </ul>
  
  <p><strong>Second set of choices:</strong></p>
  
  <ul>
  <li><kbd>x</kbd> Second Option 1</li>
  <li><kbd>x</kbd> Second Option 2</li>
  <li><kbd>x</kbd> Second Option 3</li>
  <li><kbd>x</kbd> Second Option 4</li>
  <li>etc.</li>
  </ul>
  
  <hr>
  
  <p>Checkboxes should display <code>MyViewModelClass.Area.Name</code>, and their value should be related to <code>MyViewModelClass.Area.Id</code>. Checked state is of course related to <code>MyViewModel.IsChecked</code>.</p>
  
  <h2>Question</h2>
  
  <p>I wonder how should I use <code>Html.CheckBox()</code> or <code>Html.CheckBoxFor()</code> helper to display my checkboxes? I have to get these values back to the server on a postback of course.</p>
  
  <p>I would like to have my controller action like one of these:</p>
  
  <pre><code>public ActionResult ConsumeSelections(List&lt;List&lt;MyViewModelClass&gt;&gt; data)
  {
      // process data
  }
  
  public ActionResult ConsumeSelections(List&lt;MyViewModelClass&gt; first, List&lt;MyViewModelClass&gt; second)
  {
      // process data
  }
  </code></pre>
  
  <p>If it makes things simpler, I could make a separate view model type like:</p>
  
  <pre><code>public class Options
  {
      public List&lt;MyViewModelClass&gt; First { get; set; }
  
      public List&lt;MyViewModelClass&gt; Second { get; set; }
  }
  </code></pre>
  
  <p>As well as changing my first version of controller action to:</p>
  
  <pre><code>public ActionResult ConsumeSelections(Options data)
  {
      // process data
  }
  </code></pre>