title: creating a list of anonymous type and passing to view
body: <p>i want to to display all items from my parent table with selected items from child table and create a list of them to pass to my view.  </p>
  
  <h1>Here is my action method</h1>
  
  <pre><code>public ActionResult Index()
  {
      int Month = DateTime.Now.Month;
      List&lt;EmployeeAtt&gt; empWithDate = new List&lt;EmployeeAtt&gt;();
      var employeelist = _context.TblEmployee.ToList();
  
      foreach (var employee in employeelist)
      {
          // var employeeAtt = new EmployeeAtt();
          var employeeAtt = _context.AttendanceTable
              .GroupBy(a =&gt; a.DateAndTime.Date)
              .Select(g =&gt; new
              {
                  Date = g.Key,
                  Emp_name = employee.EmployeeName,
                  InTime = g
                      .Where(e =&gt; e.ScanType == "I")
                      .Min(e =&gt; e.DateAndTime.TimeOfDay),
                  OutTime = g
                      .Where(e =&gt; e.ScanType == "O")
                      .Max(e =&gt; e.DateAndTime.TimeOfDay),
              });
      }
      return View();
  } 
  </code></pre>
  
  <h1>Here is my view</h1>
  
  <pre><code> @model IEnumerable&lt;Attendance.Models.EmployeeAtt&gt;
      @{`enter code here`
          ViewBag.Title = "AttendanceTable";
          &lt;!--Get number of days of current month--&gt;
          var DaysInmonth = DateTime.DaysInMonth(DateTime.Now.Year, DateTime.Now.Month);
          &lt;!--Create a CurrentName field--&gt;
          var CurrentName = "";
      }
  
      &lt;table class="table table-bordered"&gt;
          &lt;thead&gt;
              &lt;tr&gt;
                  &lt;th&gt;EmpName&lt;/th&gt;
                  &lt;!--Loop all the days of month and print it--&gt;
                  @for (var numb = 1; numb &lt;= DaysInmonth; numb++)
                  {
                      &lt;th&gt;@numb&lt;/th&gt;
                  }
  
              &lt;/tr&gt;
          &lt;/thead&gt;
          &lt;tbody&gt;
              &lt;!--Loop model--&gt;
              @foreach (var emp in Model)
              {
                  //if Name is repeated, skip
                  if (CurrentName != emp.Emp_name)
                  {
                      // Set Name
                      CurrentName = emp.Emp_name;
              &lt;tr&gt;
                  &lt;!--print employee name one time only at the start of row--&gt;
                  &lt;td&gt;@emp.Emp_name&lt;/td&gt;
  
                  &lt;!--loop all days of month--&gt;
                  @for (var numb = 1; numb &lt;= DaysInmonth; numb++)
                  {
                      &lt;td&gt;
                          @{
                              &lt;!--print only that date time value which is equal to current date(as it will match column header) and current employee name, else print empty--&gt;
                              var GetThatDayValue = Model.Where(a =&gt; a.Date.Value.Day == numb &amp;&amp; a.Emp_name == emp.Emp_name).FirstOrDefault();
                              var DD = GetThatDayValue != null ? GetThatDayValue.InTime + " " + GetThatDayValue.OutTime : "A";
                              &lt;text&gt; @DD &lt;/text&gt;
                          }
                      &lt;/td&gt;    
              }
              &lt;/tr&gt;
                  }
              }
          &lt;/tbody&gt;
      &lt;/table&gt;
  </code></pre>
  
  <p>How can i convert from anonymous type to concrete type so that i can make a list of view model objects ( EmployeeAtt) and access it in my view</p>