title: Create MVC3 CheckBoxFor from List<T> and getting the list back (With updated values) on Post
body: <p>I have a List in my ViewModel I parse to the View</p>
  
  <pre><code>List&lt;BoolSetting&gt; 
  </code></pre>
  
  <p>BoolSetting:</p>
  
  <pre><code>    public class BoolSetting
  {
      public BoolSetting(string displayName, bool value)
      {
          DisplayName = displayName;
          Value = value;
      }
      public string DisplayName { get; set; }
      public bool Value { get; set; }
  }
  </code></pre>
  
  <p>I then want to print a checkbox for all the items in my list, so the list is in the ViewModel the view uses</p>
  
  <pre><code>@foreach(var boolSettingList in Model.BoolSettingList)
          {
              &lt;div&gt;
                  @Html.CheckBox(boolSettingList.DisplayName, boolSettingList.Value)
                  @boolSettingList.DisplayName
              &lt;/div&gt;
          }
  </code></pre>
  
  <p>The problem is when I post this then my Model have not saved the updated settings (The bool values) in the List in my ViewModel and therefore the object is empty.</p>
  
  <p>I could do </p>
  
  <pre><code>foreach (var VARIABLE in userSettingConfigViewModel.BoolSettingList)
          {
              VARIABLE.Value = (bool)Request.Form[VARIABLE.DisplayName];
  
          }
  </code></pre>
  
  <p>But this viewmodel will have many lists and some of them will have the same names! So that will cause conflicts</p>
  
  <p>So is there a way to foreach print all my bools and then make MVC figure out to put the data back into the List object after? I cant get CheckBoxFor to work as it wants an expression and I cant figure out a way to itterate through my list that way</p>
  
  <p>Can I maybe fix it with Templates, by making a template for BoolSetting and maybe List ?</p>