title: ASP.NET MVC4 FormCollection.GetValues not returning correct values
body: <p>I'm building a mobile webiste using ASP.NET MVC4.
  One of the pages in my solution contains a table where all the rows in the table can be edited and saved in one batch. To do this I am using FormCollection in the Action in the Controller. This works as expected for most of the fields, exept one: item.IsPercent. This field is a boolean, and FormCollection.GetValues("item.IsPercent") returns twice the number of rows in the table and the list always alternates between true and false, no matter what the actual values are.</p>
  
  <p>How can I collect the right value for the Percent checkboxes?</p>
  
  <p><strong>An Example</strong></p>
  
  <p><img src="https://i.stack.imgur.com/ZxPNc.png" alt="enter image description here"></p>
  
  <p><strong>My View</strong></p>
  
  <pre><code>@using (Html.BeginForm()) {
   @Html.AntiForgeryToken()
  @Html.ValidationSummary(true)
  
  foreach (var group in Model.GroupBy(i =&gt; i.Exercise.Name)) {
  &lt;table&gt;
  &lt;tr&gt;
          &lt;th colspan="4"&gt;@Html.Label(group.Key)&lt;/th&gt;
  &lt;/tr&gt;
      &lt;tr&gt;
          &lt;td&gt;Load&lt;/td&gt;
          &lt;td&gt;Percent&lt;/td&gt;
          &lt;td&gt; &lt;/td&gt;
          &lt;td&gt;Reps&lt;/td&gt;
      &lt;/tr&gt;
   @foreach (var item in group.OrderBy(i =&gt; i.Order))
      {
  
       @Html.HiddenFor(modelItem =&gt; item.Id)
      &lt;tr&gt;
  
          &lt;td&gt;
              @Html.EditorFor(modelItem =&gt; item.Load) 
              @Html.ValidationMessageFor(modelItem =&gt; item.Load)
          &lt;/td&gt;
          &lt;td&gt;
              @Html.EditorFor(modelItem =&gt; item.IsPercent)
          &lt;/td&gt;
          &lt;td&gt;
              x
          &lt;/td&gt;
          &lt;td&gt;
              @Html.EditorFor(modelItem =&gt; item.Repetitions)
               @Html.ValidationMessageFor(modelItem =&gt; item.Repetitions)
          &lt;/td&gt;
      &lt;/tr&gt;
      }
      &lt;/table&gt;
      &lt;br /&gt;
  }
  
  &lt;p&gt;
      &lt;input type="submit" value="Save" /&gt;
  &lt;/p&gt;
  }
  </code></pre>
  
  <p><strong>My Controller</strong></p>
  
  <pre><code>[HttpPost]
      public ActionResult EditProgramTemplateLines(FormCollection c)
      {
          int i = 0;
          int ptId = 0;
          if (ModelState.IsValid)
          {
              var ptIdArray = c.GetValues("item.id"); // [1,2,3,4]
              var ptLoadArray = c.GetValues("item.Load"); // [50, 55, 60, 80]
              var ptPercentArray = c.GetValues("item.IsPercent"); // [true, false, true, false, true, false, true, false]
              var ptRepsArray = c.GetValues("item.Repetitions"); // [13, 10, 5, 2]
  
              for (i = 0; i &lt; ptIdArray.Count(); i++) {
                  var ptLine = factory.GetProgramTemplateLine(Convert.ToInt32(ptIdArray[i]));
                  if(ptId == 0)
                      ptId = ptLine.ProgramTemplateId;
  
                  ptLine.Load = ConvertToDouble(ptLoadArray[i]);
                  ptLine.IsPercent = Convert.ToBoolean(ptPercentArray[i]);
                  ptLine.Repetitions = ConvertToInt(ptRepsArray[i]);
                  factory.SetEntryAsModified(ptLine);
  
              }
              factory.SaveChanges();
              return RedirectToAction("Details", new { id = ptId });
          }
          return View();
      }
  </code></pre>
  
  <p><strong>Updated solution</strong>
  Considering the link posted in comment below <a href="https://stackoverflow.com/questions/1714989/formcollection-for-a-checkbox">FormCollection for a checkbox</a> my solution is to loop throug the array like this:</p>
  
  <pre><code>var percentId = 0;
  for(i = 0;i&lt;ptIdArray.Count();i++){
  if(ptPercentArray[percentId] == true){
  item.IsPercent = true;
  percentId = percentId + 2;
  }
  else{
  item.IsPercent = false;
  percentId++;
  }
  }
  </code></pre>