title: Passing values of checkboxes from View to Controller
body: <p>I have a view with a number of checkboxes in it. I want to be able to pass the values of the checkboxes to the controller, then output a list of the OfficeNames that have been ticked. I am not sure how to pass the values of multiple checkboxes back to the controller, or how to output the OfficeNames based on which boxes have been ticked</p>
  
  <p>View:</p>
  
  <pre><code>&lt;p&gt;
  @using (Html.BeginForm())
  {
  &lt;p&gt;
      Start Date: @Html.TextBox("StartDate") &lt;br /&gt;
      &lt;br /&gt;
      End Date: @Html.TextBox("EndDate") &lt;br /&gt;
      &lt;br /&gt;
      &lt;input type="submit" value="Filter" /&gt;
  &lt;/p&gt;
  }
  
  &lt;p&gt;
  @foreach (var item in Model.BettingOffices)
  {
      &lt;label&gt;@Html.DisplayFor(modelItem =&gt; item.OfficeName)&lt;/label&gt;
      &lt;input type="checkbox" name="selectedShops" value="@item.OfficeName"&gt;
  }
  
  &lt;/p&gt;
  </code></pre>
  
  <p>Controller:</p>
  
  <pre><code>public class DailyReportController : Controller
  {
      private RiskEntities _db = new RiskEntities();
  
      // GET: /DailyReport/
      public ActionResult Index(DateTime? startDate, DateTime? endDate)
      {
  
          if (startDate == null || endDate == null)
          {
              var dailyReportModelBlank = new DailyReportModel();
              dailyReportModelBlank.BettingOffices = (from bo in _db.BettingOffices orderby bo.OfficeName select bo ).ToList();
              //dailyReportModelBlank.DailyReports.Add(new DailyReport());
              return View(dailyReportModelBlank);
          }
  
          var endDateToUse = (DateTime) endDate;
          endDateToUse = endDateToUse.AddDays(+1);
  
  
          var dailyReportModel = new DailyReportModel
          {
              DailyReports = (from dr in _db.DailyReports
                  where dr.DailyReportDate &gt;= startDate
                        &amp;&amp; dr.DailyReportDate &lt;= endDateToUse
                  select dr).ToList(),
              BettingOffices = (from bo in _db.BettingOffices select bo).ToList()
          };
  
  
          return View(dailyReportModel);
      }
  </code></pre>
  
  <p>Model:</p>
  
  <pre><code>public class DailyReportModel
  {
      private List&lt;DailyReport&gt; _dailyReports = new List&lt;DailyReport&gt;();
      private List&lt;BettingOffice&gt; _bettingOffices = new List&lt;BettingOffice&gt;();
  
      public List&lt;DailyReport&gt; DailyReports
      {
          get { return _dailyReports; }
          set { _dailyReports = value; }
      }
  
      public List&lt;BettingOffice&gt; BettingOffices
      {
          get { return _bettingOffices; }
          set { _bettingOffices = value; }
      }
  }
  </code></pre>
  
  <p>BettingOffice Class:</p>
  
  <pre><code>public partial class BettingOffice
  {
      public int BettingOfficeID { get; set; }
      public string OfficeName { get; set; }
      public string OfficeCode { get; set; }
      public string IpAddress { get; set; }
      public Nullable&lt;bool&gt; SupportOnly { get; set; }
      public Nullable&lt;int&gt; SisSrNumer { get; set; }
      public Nullable&lt;bool&gt; Local { get; set; }
      public string Server { get; set; }
  }
  </code></pre>