title: Getting Checkbox Values on postback ASP.NET MVC
body: <p>I am writing an ASP.NET MVC application. I am a beginner so I'm sure this is really easy. I referenced <a href="https://stackoverflow.com/questions/1495038/asp-net-mvc-how-to-get-checkbox-values-on-post">ASP.NET MVC - How to get checkbox values on post</a> but the code isn't available anymore, making it next to useless.</p>
  
  <p>Here is my View:</p>
  
  <pre><code>@using (@Html.BeginForm("Promote", "FPL", FormMethod.Post))
  {
  &lt;div data-role="fieldcontain"&gt;
  &lt;fieldset id="PromotionInfo" name="PromotionInfo"&gt;
  &lt;legend&gt;&lt;b&gt;@Model.itemType Promotion Details&lt;/b&gt;&lt;/legend&gt;
      &lt;label for="TargetDate"&gt;Target Date: &lt;/label&gt;
      &lt;input type="date" id="TargetDate" data-role="datebox" data-options='{"mode": "flipbox"}' /&gt;
  
      &lt;label for="EmailCC"&gt;Email cc List: &lt;/label&gt;
      &lt;input type="email" id="EmailCC" /&gt;
  
      &lt;div  data-role="fieldcontain"&gt;
      &lt;fieldset data-role="controlgroup"&gt;
      &lt;legend&gt;Choose Destination Server(s): &lt;/legend&gt;
  
      @foreach (DataRow server in Model.destinationServerList.Rows)
      {
      &lt;label for="@server.ItemArray[0]"&gt;@server.ItemArray[1]&lt;/label&gt;  
      &lt;input type="checkbox" name="destinationServerSID" id="@server.ItemArray[0].ToString()"  /&gt;
      }
  
      &lt;/fieldset&gt;
      &lt;/div&gt;
  &lt;/fieldset&gt;
  
  &lt;/div&gt;
  
  &lt;input type="submit" value="Submit" /&gt;
  } 
  </code></pre>
  
  <p>And here is my Controller:</p>
  
  <pre><code>    public ActionResult Promote(string id)
      {
          //Model(item) construction occurs here
  
          return View(item);
      }
  
      [HttpPost]
      public ActionResult Promote(FormCollection collection)
      {
          try
          {
              string[] test = collection.GetValues("destinationServerSID");
          }
          catch (Exception ex)
          {
              return null;
          }
      }
  </code></pre>
  
  <p>The test[] variable contains a 2 item array, both of which have the value "on" however, my list of items is longer than 2 items. It simply contains an "on" for every value you select, but no "off" values. I need the actual value of the checkbox(the id field).</p>