title: Can't get ICollection entities from MVC View
body: <p>So I am making an app for a restaurant that is able to handle Event Table Reservations.</p>
  <p>What I want to have is an Event model, and a Table model where I will be able to create tables and use them for each event I create afterwards.</p>
  <p>The problem is that after I get the tables in the Event Creation, I am not able to save these tables as copies for the Event(more precisely @event.Tables in Create Post is empty):<br/></p>
  <p>Event model:</p>
  <pre><code>public class Event
      {
          public Event()
          {
              this.Tables = new HashSet&lt;Table&gt;();
          }
  
          public int Id { get; set; }
          public string EventName { get; set; }
  
          public String StartDate { get; set; }
          
          public String StartTime { get; set; }
          public string ImageURL { get; set; }
          public string Description { get; set; }
  
          public virtual ICollection&lt;Table&gt; Tables { get; set; }
  
      }
  
  </code></pre>
  <p>Table model:</p>
  <pre><code> public class Table //Model for Table Conf
      {
          public enum ReservationState {
              [Display(Name = &quot;Available&quot;)]
              Available,
              [Display(Name = &quot;Processing&quot;)]
              Processing,
              [Display(Name = &quot;Reserved&quot;)]
              Reserved
          }
          public int Id { get; set; }
          public int Price { get; set; }
          public string TableIdentifier { get; set; }
          public int NPeople { get; set; }
          public ReservationState ReservationStatus { get; set; }
          public virtual int? EventId { get; set; }
  
      }
  </code></pre>
  <p>EventsController:</p>
  <pre><code> // GET: Events/Create
          public IActionResult Create()
          {
              List&lt;Table&gt; tables = _context.Table.Where(t =&gt; t.EventId == null).AsNoTracking().ToList();
              Event newEvent = new Event();
              foreach(Table table in tables)
              {
                  newEvent.Tables.Add(table);
              }
              return View(newEvent);
          }
  
          // POST: Events/Create
          [HttpPost]
          [ValidateAntiForgeryToken]
          public async Task&lt;IActionResult&gt; Create([Bind(&quot;Id,EventName,StartDate,StartTime,ImageURL,Description,Tables&quot;)] Event @event)
          {
              if (ModelState.IsValid)
              {
                  foreach (Table table in @event.Tables)
                  {
                      Table cloneTable = new Table();
                      _context.Table.Add(cloneTable);
                      int cloneId = cloneTable.Id;
                      var sourceValues = _context.Entry(table).CurrentValues;
                      _context.Entry(cloneTable).CurrentValues.SetValues(sourceValues);
  
                      cloneTable.EventId = @event.Id;
                      cloneTable.Id = cloneId;
                      
                  }
                  _context.Add(@event);
                  await _context.SaveChangesAsync();
                  
                  return RedirectToAction(nameof(Index));
              }
              return View(@event);
          }
  </code></pre>
  <p>Event Create View(the part for saving tables, since everything else is working fine, also I can see the tables in the view correctly:</p>
  <pre><code>&lt;div class=&quot;form-group&quot;&gt;
  
                  @for (var i = 0; i &lt; Model.Tables.Count; i++)
                  {
  
                      &lt;p&gt;@Model.Tables.ElementAt(i).TableIdentifier - @Model.Tables.ElementAt(i).ReservationStatus  - @Model.Tables.ElementAt(i).Id &lt;/p&gt;
                      &lt;input type=&quot;hidden&quot; asp-for=&quot;@Model.Tables.ElementAt(i).Id&quot; name=&quot;@Model.Tables.ElementAt(i).Id&quot;
                             value=&quot;@Model.Tables.ElementAt(i).Id&quot; /&gt;
                      &lt;input type=&quot;hidden&quot; asp-for=&quot;@Model.Tables.ElementAt(i).NPeople&quot; name=&quot;@Model.Tables.ElementAt(i).NPeople&quot;
                             value=&quot;@Model.Tables.ElementAt(i).NPeople&quot; /&gt;
                      &lt;input type=&quot;hidden&quot; asp-for=&quot;@Model.Tables.ElementAt(i).Price&quot; name=&quot;@Model.Tables.ElementAt(i).Price&quot;
                             value=&quot;@Model.Tables.ElementAt(i).Price&quot; /&gt;
                      &lt;input type=&quot;hidden&quot; asp-for=&quot;@Model.Tables.ElementAt(i).TableIdentifier&quot; name=&quot;@Model.Tables.ElementAt(i).TableIdentifier&quot;
                             value=&quot;@Model.Tables.ElementAt(i).TableIdentifier&quot; /&gt;
                      &lt;input type=&quot;hidden&quot; asp-for=&quot;@Model.Tables.ElementAt(i).EventId&quot; name=&quot;@Model.Tables.ElementAt(i).EventId&quot;
                             value=&quot;@Model.Tables.ElementAt(i).EventId&quot; /&gt;
                      &lt;select asp-for=&quot;@Model.Tables.ElementAt(i).ReservationStatus&quot; name=&quot;@Model.Tables.ElementAt(i).ReservationStatus&quot; asp-items=&quot;Html.GetEnumSelectList&lt;Table.ReservationState&gt;()&quot;&gt;
                      &lt;/select&gt;
                  }
  &lt;/div&gt;
  </code></pre>