title: Why do I receive null values in my controller when I submit a form from a view with multiple forms? With ASP.NET Core 5 MVC
body: <p>I am developing a web application using ASP.NET Core 5 MVC, in which I seek to make multiple submissions of <code>POST</code> type forms to my controller from a view that receives an <code>IEnumerable</code> (from a model called <code>Result</code>) with which I am filling in dynamically the values of the inputs of each form.</p>
  <p>However, when I send one of those forms from the view through the controller, in the controller I only receive an object from the model with all the null or empty values, which tells me that it seems that this data was never sent through the form to my controller.</p>
  <p>Is there a better way to accomplish this or how do I pass these values from multiple forms to my controller? In advance an apology if what I am doing is already totally wrong, I have been learning ASP.NET Core MVC for a few days.</p>
  <p><strong>CONSIDERATIONS</strong></p>
  <p>What I seek to achieve is that the user can enter multiple values that belong to the same model in the same view, since each form although it is the same seeks to update a different record or column in the same model or table, so when the submit of the form is sent to the Controller the view does not change, and only the records in the database are updated with each submit in the view. If there is a better way or correct way to do this, I am willing to change the logic, because as I mentioned, I have been using the Framework for little.</p>
  <p>Explained the problem and my goal, I will explain in greater detail the flow and code mentioned:</p>
  <ol>
  <li><p>From the <code>Mechanical</code> method of my controller, I return a list of Objects to their corresponding View, which are brought by a <code>DataBaseContext</code>:</p>
  <pre><code> // CONTROLLER() that passes an enumerable list of Objects to View Mechanical.cshtml
   public IActionResult Mechanical()
   {
       IEnumerable&lt;Result&gt; objList = _db.Results;
       return View(objList);
   }
  </code></pre>
  </li>
  <li><p>In the <code>Mechanical()</code> view, I get this list of objects and iterate over it through a <code>forEach()</code> loop, where for each object I create a form that directs to the same controller method called <code>Update()</code>, in which I get the values of the object in null and empty (that being my problem):</p>
  </li>
  </ol>
  <pre class="lang-cs prettyprint-override"><code>// VIEW
  @model IEnumerable&lt;FatForm.Models.Result&gt;
  
  @if (Model.Count() &gt; 0)
  {
      @foreach(var result in Model)
      {
          &lt;form method=&quot;post&quot; asp-action=&quot;Update&quot;&gt;
              &lt;input asp-for=&quot;@result.Id&quot; hidden /&gt;
              &lt;input asp-for=&quot;@result.Type&quot; hidden /&gt;
              &lt;input asp-for=&quot;@result.FatId&quot; hidden /&gt;
              &lt;div class=&quot;border p-3&quot;&gt;
                  &lt;div class=&quot;form-group row&quot;&gt;
                      &lt;h2 class=&quot;text-black-50 pl-3&quot;&gt;Edit Result&lt;/h2&gt;
                  &lt;/div&gt;
                  &lt;div class=&quot;row&quot;&gt;
                      &lt;div class=&quot;col-12&quot;&gt;
                          &lt;div class=&quot;form-group row&quot;&gt;
                              &lt;div class=&quot;col-3&quot;&gt;
                                  &lt;label asp-for=&quot;@result.Section&quot;&gt;&lt;/label&gt;
                              &lt;/div&gt;
                              &lt;div class=&quot;col-3&quot;&gt;
                                  &lt;label asp-for=&quot;@result.Procedure&quot;&gt;&lt;/label&gt;
                              &lt;/div&gt;
                              &lt;div class=&quot;col-3&quot;&gt;
                                  &lt;label asp-for=&quot;@result.ResultDescription&quot;&gt;&lt;/label&gt;
                              &lt;/div&gt;
                              &lt;div class=&quot;col-3&quot;&gt;
                                  &lt;label asp-for=&quot;@result.Passed&quot;&gt;&lt;/label&gt;
                              &lt;/div&gt;
                          &lt;/div&gt;
                          &lt;div class=&quot;form-group row&quot;&gt;
                              &lt;div class=&quot;col-3&quot;&gt;
                                  &lt;input asp-for=&quot;@result.Section&quot; class=&quot;form-control&quot; /&gt;
                              &lt;/div&gt;
                              &lt;div class=&quot;col-3&quot;&gt;
                                  &lt;input asp-for=&quot;@result.Procedure&quot; class=&quot;form-control&quot; /&gt;
                              &lt;/div&gt;
                              &lt;div class=&quot;col-3&quot;&gt;
                                  &lt;input asp-for=&quot;@result.ResultDescription&quot; class=&quot;form-control&quot; /&gt;
                                  &lt;span asp-validation-for=&quot;@result.ResultDescription&quot; class=&quot;text-danger&quot;&gt;&lt;/span&gt;
                              &lt;/div&gt;
                              &lt;div class=&quot;col-3&quot;&gt;
                                  &lt;input asp-for=&quot;@result.Passed&quot; class=&quot;form-control&quot; /&gt;
                                  &lt;span asp-validation-for=&quot;@result.Passed&quot; class=&quot;text-danger&quot;&gt;&lt;/span&gt;
                              &lt;/div&gt;
                          &lt;/div&gt;
                          &lt;div class=&quot;form-group row&quot;&gt;
                              &lt;div class=&quot;col-8 offset-2 row&quot;&gt;
                                  &lt;div class=&quot;col&quot;&gt;
                                      &lt;input type=&quot;submit&quot; class=&quot;btn btn-info w-75&quot; value=&quot;Save&quot; /&gt;
                                  &lt;/div&gt;
                              &lt;/div&gt;
                          &lt;/div&gt;
  
                      &lt;/div&gt;
                  &lt;/div&gt;
              &lt;/div&gt;
          &lt;/form&gt;        
      }
  }
  else
  {
      &lt;p&gt;No results created yet&lt;/p&gt;
  }
  
  @section Scripts{
      @{
          &lt;partial name=&quot;_ValidationScriptsPartial&quot; /&gt;
      }
  }
  </code></pre>
  <ol start="3">
  <li><p>I'm supposed to be looking to send the form values to the following <code>Update()</code> controller method, in which I get all the object values to null:</p>
  <pre><code> // POST Update
   [HttpPost]
   [ValidateAntiForgeryToken]
   public IActionResult Update(Result obj)
   {
       if (ModelState.IsValid)
       {
           _db.Results.Update(obj);
           _db.SaveChanges();
           //return RedirectToAction(&quot;Index&quot;);
       }
  
       return View(obj);
   }
  </code></pre>
  </li>
  </ol>
  <p><a href="https://i.stack.imgur.com/D0LRf.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/D0LRf.png" alt="Here you can see the null values on the controller from the view" /></a></p>
  <p>As I explained at the beginning, I hope can help me by indicating what I am doing wrong or in what way I should do it. Thanks in advance for your help.</p>