title: Asp.Net MVC : Insert data from form collection with List of values
body: <p>As you can see in picture, I have a form where I continuously add items to the table below.</p>
  
  <p>When I click "Save all" button, it posts all the table values to "<strong>InsertBulk</strong>" method. 
  <a href="https://i.stack.imgur.com/jsBoR.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/jsBoR.png" alt="enter image description here"></a></p>
  
  <p>And this is what I did in my view. I am created a form within the table. Set name and values for each input field. Made the input fields hidden, displayed only text and then on clicking <strong>save all</strong> button it posts all those value to the <strong>InsertBulk</strong> method.
  <div class="snippet" data-lang="js" data-hide="false" data-console="false" data-babel="false">
  <div class="snippet-code">
  <pre class="snippet-code-html lang-html prettyprint-override"><code>@model FYPPharmAssistant.Models.InventoryModel.Manufacturer
  
  @{
      ViewBag.Title = "Form";
      Layout = "~/Views/Shared/_Layout.cshtml";
  }
  
  
  @using (Html.BeginForm()) 
  { 
      &lt;label&gt;Name&lt;/label&gt;&lt;br /&gt;
      @Html.EditorFor(m =&gt; m.ManufacturerName, new { htmlAttributes = new { @class = "form-control" } })  &lt;br /&gt;
      &lt;label&gt;Description&lt;/label&gt;&lt;br /&gt;
      @Html.EditorFor(m =&gt; m.Description, new { htmlAttributes = new { @class = "form-control" } })
      &lt;input type="submit" id="addmore" value="add" /&gt;
  }
  @using (Html.BeginForm("InsertBulk", "Manufacturer"))
  {
      &lt;table id="table"&gt;
          &lt;tr&gt;
              &lt;th&gt;
                  name &amp;nbsp; &amp;nbsp; 
              &lt;/th&gt;
              &lt;th&gt;
                  description
              &lt;/th&gt;
          &lt;/tr&gt;
      &lt;/table&gt;
      &lt;input type="submit" id="btnsaveall" value="Save all" /&gt;
  }
  
  &lt;script&gt;
      $(document).on('ready', function () {
          $('#addmore').on('click', function () {
              var $table = $("#table");            
              $table.append("&lt;tr&gt; &lt;td&gt;&lt;input type='hidden' name='ManufacturerName' value='" + $('#ManufacturerName').val() + "' /&gt;" + $('#ManufacturerName').val() + "&lt;/td&gt; &lt;td&gt;&lt;input type='hidden' name='Description' value='" + $('#Description').val() + "'&gt;" + $('#Description').val() + "&lt;/td&gt; &lt;td&gt;&lt;a href='javascript:void(0)' onclick='removeItem(this)'&gt;Remove&lt;/a&gt;&lt;/td&gt;&lt;/tr&gt;");
  
              return false;
          });
        });
    &lt;/script&gt;</code></pre>
  </div>
  </div>
  </p>
  
  <p>This is my <strong>InsertBulk</strong> method. </p>
  
  <p><div class="snippet" data-lang="js" data-hide="false" data-console="false" data-babel="false">
  <div class="snippet-code">
  <pre class="snippet-code-js lang-js prettyprint-override"><code>[HttpPost]
          public void InsertBulk(FormCollection coll)
          {
             
                  Manufacturer m = new Manufacturer();
                  m.ManufacturerName = coll["ManufacturerName"];
                  m.Description = coll["Description"];
                  db.Manufacturers.Add(m);
                  db.SaveChanges();
            
            }</code></pre>
  </div>
  </div>
  </p>
  
  <p><strong>Result :</strong>
  Ans this is what I get in Result. How am I suppose to solve this ? Please help! </p>
  
  <p><a href="https://i.stack.imgur.com/tZCZG.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/tZCZG.png" alt="enter image description here"></a></p>
  
  <p>I also tried to count keys and loop through each in the <strong>InsertBulk</strong> method. But I think I did it all wrong. </p>
  
  <p><div class="snippet" data-lang="js" data-hide="false" data-console="false" data-babel="false">
  <div class="snippet-code">
  <pre class="snippet-code-html lang-html prettyprint-override"><code> int count = coll.Count;
              
  
                if(count == 0)
                {
                    return View("ChamForm", "Test");
                }
                else
                {
                    for(int i = 0; i&lt;count; i++)
                    {
                        Manufacturer m = new Manufacturer();
                        m.ManufacturerName = coll["ManufacturerName[" + i + "]"];
                        m.Description = coll["Description[" + i + "]"];
                        db.Manufacturers.Add(m);
                        db.SaveChanges();
                    }
                }*</code></pre>
  </div>
  </div>
  </p>