title: How do I insert multiple input entries at one time in .NET Core MVC 2.2
body: <p>I'm running into a problem when adding multiple input entries at once. Below I have put all information I think you'll need. </p>
  
  <p><b>View:</b> <a href="http://prntscr.com/qto52o" rel="nofollow noreferrer">http://prntscr.com/qto52o</a>
  <br><b>View code:</b></p>
  
  <pre><code>                @foreach (var item in ViewBag.Studenten)
              {
                  &lt;input name="vakId" value="@vakId" style="display:none;"/&gt;
                  &lt;input name="studentId" value="@item.Id" style="display:none;" /&gt;
                  &lt;label&gt;@item.Voornaam @item.Tussenvoegsel @item.Achternaam&lt;/label&gt;
                  &lt;input type="number" class="form-control" min="1" max="10" step="0.2" /&gt;
                  &lt;span id="Validation" class="text-danger"&gt;&lt;/span&gt;
                  &lt;br /&gt;
              }
  </code></pre>
  
  <p><b>Method:</b></p>
  
  <pre><code> [HttpPost]
      [ValidateAntiForgeryToken]
      public async Task&lt;IActionResult&gt; GroepsResultaten(int vakId, int[] studentId, [Bind("Id,Beoordeling,StudentId,VakId")] List&lt;Resultaat&gt; resultatenLijst, Resultaat resultaat)
      {
          Console.WriteLine("vakId is :" + vakId);
          if (ModelState.IsValid)
          {
              List&lt;Student&gt; Studenten = new List&lt;Student&gt;();
              foreach (var student in studentId)
              {
                  resultaat.StudentId = student;
                  resultaat.Beoordeling = 9;
                  resultaat.VakId = vakId;
                  Console.WriteLine("studentId is :" + student.ToString());
                  _context.Add(resultaat);
              }
              await _context.SaveChangesAsync();
              return RedirectToAction(nameof(Index));
          }
          ViewData["StudentId"] = new SelectList(_context.Student, "Id", "Voornaam", resultaat.StudentId);
          ViewData["VakId"] = new SelectList(_context.Set&lt;Vak&gt;(), "Id", "Naam", resultaat.VakId);
          return View(resultaat);
      }
  </code></pre>
  
  <p><b>Models used: </b></p>
  
  <pre><code>  public class Resultaat
  {
      public int Id { get; set; }
      public double Beoordeling { get; set; }
  
      public Student Student { get; set; }
      public int StudentId { get; set; }
  
      public Vak Vak { get; set; }
      public int VakId { get; set; }
  }
  public class Vak
  {
      public int Id { get; set; }
      [Required]
      public string Naam { get; set; }
      [Required]
      public string Vakcode { get; set; }
  
      public List&lt;Resultaat&gt; Resultaten { get; set; }
      public List&lt;GroepVak&gt; Groepen { get; set; }
  }
      public class Student
  {
      public int Id { get; set; }
      [Required]
      public string Voornaam { get; set; }
      [Required]
      public string Achternaam { get; set; }
      public string Tussenvoegsel { get; set; }
      public string Studentnummer { get; set; }
  
      public List&lt;Resultaat&gt; Resultaten { get; set; }
      public List&lt;StudentGroep&gt; Groepen { get; set; }
  }
  </code></pre>
  
  <p>Writing studentId's and subjectId's works fine in console, I think the problem is adding the values into the database.</p>
  
  <p><b>Edit:</b>
  <br>It only inserts values for the last student from the create view</p>