title: How do you add a table list to a ViewModel in .net core
body: <p>I have a User model.</p>
  
  <pre><code>public class User
  {
      public int Id { get; set; }
      [Required]
      public string FirstName { get; set; }
      [Required]
      public string LastName { get; set; }
      [Required]
      public int UserGroupId { get; set; }
      public UserGroup UserGroup { get; set; }
  }
  </code></pre>
  
  <p>This is is my UserGroup model that would contain user groups like Admin, System Admin, etc.</p>
  
  <pre><code>public class UserGroup
  {
      public int Id {get; set;}
      public bool Admin {get; set;}
      public bool SystemAdmin {get; set}
      public List&lt;User&gt; Users {get; set;}
  }
  </code></pre>
  
  <p>I just started .net core so I hope my relationship is correct. 
  What I would like is to have a User Create View that had a html selection that list all the groups. Something like this but being dynamic.</p>
  
  <pre><code>&lt;select class="form-control m-b" asp-for="Role" required&gt;
      &lt;option value=""&gt;&lt;/option&gt; 
      &lt;option value="Admin"&gt;Admin&lt;/option&gt;
      &lt;option value="SystemAdmin"&gt;System Admin&lt;/option&gt;
  &lt;/select&gt;
  </code></pre>
  
  <p>This is the UserGroupViewModel that I'm send to the User Create Form.</p>
  
  <pre><code>public class UserCreateViewModel
  {
      [Required]
      public string FirstName { get; set; }
      [Required]
      public string LastName { get; set; }
      [Required]
      public List&lt;UserGroup&gt; UserGroups {get; set;}
  }
  </code></pre>
  
  <p>Finally on my UserController I'm going to be looping the List of UserGroups that I got from my database and I'll add it to the UserCreateViewModel.</p>
  
  <pre><code>public IActionResult Create()
      {
          UserCreateViewModel userCreateViewModel = new UserCreateViewModel();
  
          var userGroups = db.UserGroups.ToList();
  
          foreach(var group in userGroups)
          {
              userCreateViewModel.UserGroups.Add(group);
          }
  
  
          return View(userCreateViewModel);
      }
  </code></pre>
  
  <p>The problem is that I'm getting an error that I'm not sure how to deal with it.</p>
  
  <p><a href="https://i.stack.imgur.com/CRZHt.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/CRZHt.png" alt="enter image description here"></a>
  What does this error means and How can I solve it. I'm also open for a different approach from experience developers.</p>