title: Passing complex model to controller with .net core 3 mvc
body: <p>I had this issue before and fixed it with replacing foreach loop with For loop.
  But with .net core 3, this doesn't work anymore. The child object inside the parent object returns null. </p>
  
  <p>Basically i am developing a employee training booking system for selected staff. 
  I have got a employeeList with select checkbox. And TraineeList to save selected employee from Employee list </p>
  
  <pre><code>public class TraineeListVM
  {
      public List&lt;TraineeListModel&gt; TraineeList { get; set; }
      public List&lt;BookingEmpVM&gt; EmployeeList { get; set; }
      public BookingModel BookingModel { get; set; }
  }
  
  public class BookingEmpVM
  {
      public EmployeeModel EmployeeModel { get; set; }
      public DateTime TrainingExpData { get; set; }
      public bool EmpSelected { get; set; } = false;
  }
  </code></pre>
  
  <p>To Populate data </p>
  
  <pre><code>        public IActionResult Index(int bookingID)
      {
          List&lt;TraineeListModel&gt; Tlist = traineeListRepository.TraineeLists.Where(b =&gt; b.BookingID == bookingID).ToList();
          List&lt;EmployeeModel&gt; EmpList = employeeRepository.EmployeeList.Where(e =&gt; e.EmployeeStatus == true).ToList();
          List&lt;BookingEmpVM&gt; EmpListWithExpDate = new List&lt;BookingEmpVM&gt;();
          int i = 0;
  
          foreach (var emp in EmpList)
          {
              i++;
              EmpListWithExpDate.Add(new BookingEmpVM
              {
                  EmployeeModel = new EmployeeModel
                  {
                      EmployeeID = emp.EmployeeID,
                      Name = emp.FullName,
                      ProjectModel = emp.ProjectModel
                  },
                  EmpSelected = false,
                  TrainingExpData = DateTime.Now
              });
  
              if (i == 30) break;
          }
          return View(new TraineeListVM
          {
              TraineeList = Tlist,
              EmployeeList = EmpListWithExpDate,
              BookingModel = bookingRepository.BookingList.FirstOrDefault(b =&gt; b.BookingID == bookingID)
          });
      }
  </code></pre>
  
  <p>in cshtml</p>
  
  <pre><code> @for (int i = 0; i &lt; Model.EmployeeList.Count(); i++)
   {
       &lt;tr&gt;
          &lt;td&gt;
               @Model.EmployeeList[i].EmployeeModel.EmployeeID
          &lt;/td&gt;
          &lt;td&gt;
               @Model.EmployeeList[i].EmployeeModel.FullName
          &lt;/td&gt;
          &lt;td&gt;                                                    
               @Model.EmployeeList[i].EmployeeModel.ProjectModel.ProjectName
          &lt;/td&gt;
          &lt;td&gt;
                @Model.EmployeeList[i].TrainingExpData.ToShortDateString()
          &lt;/td&gt;
          &lt;td&gt;
                 &lt;input asp-for="@Model.EmployeeList[i].EmpSelected" /&gt;
          &lt;/td&gt;
        &lt;/tr&gt;
      }
  </code></pre>
  
  <p>Number of returned EmployeeList iscorrect but EmployeeModel inside the EmployeeList is null.
  <a href="https://i.stack.imgur.com/OLISF.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/OLISF.png" alt="enter image description here"></a></p>