title: How can I correctly use ViewModel to build a two way binding with the view when capturing input records?
body: <p>I have a form that needs to capture values from checkboxes in a form. Each checkbox should have an integer value and when the form is submitted, the view model should validate the values and at least one should be selected.</p>
  
  <p>I need to also build a two way binding so that the framework will auto select the options that are selected when the page is loaded.</p>
  
  <p>Here is what my model looks like</p>
  
  <pre><code>public class SomeViewModel 
  {
      [Required(ErrorMessage = "You must select at least one site.")]
      [Display(Name = "All site to have access too")]
      public int[] Sites { get; set; }
  }
  </code></pre>
  
  <p>The I encapsulate my ViewModel in a Presentation class called <code>Presenter</code> like so</p>
  
  <pre><code>public class Presenter
  {
      public SomeViewModel Access { get; set; }
  
      public IEnumerable&lt;Site&gt; AvailableSites { get; set; }
  }
  </code></pre>
  
  <p>Now, I pass <code>Presenter</code> to my view and want to render the</p>
  
  <p>And here is how my view looks like</p>
  
  <pre><code>&lt;div class="form-group"&gt;
  
      @Html.LabelFor(m =&gt; m.Access.Sites, new { @class = "col-sm-2 control-label" })
  
      &lt;div class="col-sm-10"&gt;
  
          @for (int i = 0; i &lt; Model.AvailableSites.Count(); i++ )
          {
              &lt;label class="radio-inline"&gt;
                  @Html.CheckBoxFor(m =&gt; m.Access.Sites[i]) 
              &lt;/label&gt;
          }
  
      &lt;/div&gt;
  
      @Html.ValidationMessageFor(m =&gt; m.Access.Sites)
  &lt;/div&gt;
  </code></pre>
  
  <p>since <code>@Html.CheckBoxFor</code> accepts bool value, and I am passing an integer I am getting an error  on the <code>@Html.CheckBoxFor(m =&gt; m.Access.Sites[i])</code> line inside the view.</p>
  
  <p>How can I correct this issue? and how can I correctly render checkboxes in this view?</p>