title: Pass list value to view model class variable in ASP.NET MVC
body: <p>I need to pass list of records to class variable (Users and Groups) in view model but I cannot seeing view model object (_UserAndGroupModel) recognizing its class object, I am not sure exactly what I am missing here. </p>
  
  <h2>ViewModel</h2>
  
  <pre><code> public class UserGroup_ViewModel
  {
      public User Users { get; set; }
      public Group Groups { get; set; }
  }
  </code></pre>
  
  <p>each class user and group have their variables and collection Items</p>
  
  <p>In following lines of code I need to pass list and and assign to user object and groups object within the view model</p>
  
  <pre><code> public partial class UserManagement_Services 
  {
      List&lt;UserGroup_ViewModel&gt; _UserAndGroupModel = new List&lt;UserGroup_ViewModel&gt;();
  
      public void GetUserAndGroups()
      {
          using(var _uow = new UserManagement_UnitOfWork())
          {
              _UserAndGroupModel.Users= _uow.User_Repository.GetAll();
              _UserAndGroupModel.Groups = _uow.Group_Repository.GetAll();
  
           //error here   ??????????????
          }
      }
  }
  </code></pre>
  
  <p><img src="https://i.stack.imgur.com/K76Kh.png" alt="enter image description here"></p>
  
  <h2>Controller Method</h2>
  
  <pre><code>  public ActionResult AddUserInGroup()
      {
          var _UserAndGroupList = _userServices.GetUserAndGroups();
  
          return PartialView("AddUserInGroup_Partial", _UserAndGroupList);
      }
  </code></pre>
  
  <h2>View</h2>
  
  <pre><code>@model IEnumerable&lt;App.DAL.Model.UserGroup_ViewModel&gt;
  </code></pre>
  
  <p>
      
          
              
                  @Html.DisplayNameFor(model => model)
              
              
                  @Html.DisplayNameFor(model => model.LastName)
              
              
                  @Html.DisplayNameFor(model => model.Age)
              
              
                  @Html.DisplayNameFor(model => model.EmailAddress)
              
              
          </p>
  
  <pre><code>    @foreach (var item in Model)
      {....
  </code></pre>
  
  <p>In view I cannot see ViewModel class variable when I do model => model.????</p>