title: Loop List In View And Bind Values to Model Depending on List Index
body: <p>I have this Model:</p>
  
  <pre><code>public class ClassRoom
  {
      public List&lt;Student&gt; Students { get; set; }
  }
  public class Student
  {
      public int ID { get; set; }
      public int Type { get; set; }
      public string Name { get; set; }
      public string LastName { get; set; }
  }
  </code></pre>
  
  <p>The values of the ID and Type are already full, I need to create a view where the student can add his name and last name.
  So I need to loop the list of students in the view.</p>
  
  <p>I am doing the following:</p>
  
  <pre><code>@model Models.ClassRoom
  
  @{
      ViewBag.Title = "Classroom";
  }
  
  
  @if (Model != null)
  {
  &lt;form action="Controller/Method"&gt;
      foreach (var item in Model.Students)
      {
          @Html.HiddenFor(model =&gt; model.ID) 
          &lt;div&gt;
              @Html.TextBoxFor(model =&gt; model.Name)
              @Html.TextBoxFor(model =&gt; model.LastName)
          &lt;/div&gt;
  
      }
      &lt;input type="submit"&gt;
    &lt;/form&gt;
    }
  </code></pre>
  
  <p><strong>I want to eventually submit a model of type Classroom with a list of students filled with Name and Last Name for each ID</strong></p>
  
  <p>But this is not working.</p>
  
  <p>How can I bind values From the View to item <strong>on a certain index in a list?</strong></p>
  
  <p>For each ID in the hidden input,I want to save the written name and last name.</p>
  
  <p>Please help</p>
  
  <p>I need to create a form and submit the ClassRoom with a full List of Students eventually. What should be the types in my Controller method and views?</p>