title: How do I render a group of checkboxes using MVC 4 and View Models (strongly typed)
body: <p>I'm rather new to the ASP.net MVC world and I'm trying to figure out how to render a group of checkboxes that are strongly typed to a view model.  In webforms I would just use the checkboxlist control but im a bit lost with MVC.</p>
  
  <p>I'm building a simple contact form for a wedding planning business and need to pass whatever checkbox values the user selects to my controller.</p>
  
  <p>The form checkboxes need to look like this:
  <img src="https://i.stack.imgur.com/hWwLQ.gif" alt="enter image description here"></p>
  
  <p>Your help would be greatly appreciated. Thanks!</p>
  
  <p>Here's what I have so far.</p>
  
  <p>CONTROLLER</p>
  
  <pre><code>[HttpPost]
  public ActionResult Contact(ContactViewModel ContactVM)
  {
      if (!ModelState.IsValid)
      {
          return View(ContactVM);
      }
      else
      {
          //Send email logic
  
          return RedirectToAction("ContactConfirm");
      }
  }
  </code></pre>
  
  <p>VIEW MODEL</p>
  
  <pre><code>public class ContactViewModel
  {
      [Required]
      public string Name { get; set; }
  
      [Required]
      public string Phone { get; set; }
  
      [Required]
      [DataType(DataType.EmailAddress)]
      public string Email { get; set; }
  
      [Required]
      public string Subject { get; set; }
      public IEnumerable&lt;SelectListItem&gt; SubjectValues
      {
          get
          {
              return new[]
              {
                  new SelectListItem { Value = "General Inquiry", Text = "General Inquiry" },
                  new SelectListItem { Value = "Full Wedding Package", Text = "Full Wedding Package" },
                  new SelectListItem { Value = "Day of Wedding", Text = "Day of Wedding" },
                  new SelectListItem { Value = "Hourly Consultation", Text = "Hourly Consultation" }  
              };
          }
      }
  
  
      //Not sure what I should do for checkboxes...
  
  }
  </code></pre>
  
  <p>VIEW</p>
  
  <pre><code>@model NBP.ViewModels.ContactViewModel
  
  @{
      ViewBag.Title = "Contact";
      Layout = "~/Views/Shared/_Layout.cshtml";
  }
  
  @using (Html.BeginForm())
  {
      &lt;div id="ContactContainer"&gt;
          &lt;div&gt;&lt;span class="RequiredField"&gt;*&amp;nbsp;&lt;/span&gt;Your Name:&lt;/div&gt;
          &lt;div&gt;
              @Html.TextBoxFor(model =&gt; model.Name)
          &lt;/div&gt;
          &lt;div&gt;&lt;span class="RequiredField"&gt;*&amp;nbsp;&lt;/span&gt;Your Phone:&lt;/div&gt;
          &lt;div&gt;
              @Html.TextBoxFor(model =&gt; model.Phone)
          &lt;/div&gt;
          &lt;div&gt;&lt;span class="RequiredField"&gt;*&amp;nbsp;&lt;/span&gt;Your Email:&lt;/div&gt;
          &lt;div&gt;
              @Html.TextBoxFor(model =&gt; model.Email)
          &lt;/div&gt;
          &lt;div&gt;Subject:&lt;/div&gt;
          &lt;div&gt; 
              @Html.DropDownListFor(model =&gt; model.Subject, Model.SubjectValues)
          &lt;/div&gt;
          &lt;div&gt;Vendor Assistance:&lt;/div&gt;
          &lt;div&gt;
  
              &lt;!-- CHECKBOXES HERE --&gt;
  
          &lt;/div&gt;
          &lt;div&gt;
              &lt;input id="btnSubmit" type="submit" value="Submit" /&gt;
          &lt;/div&gt;
      &lt;/div&gt;
  }
  </code></pre>