I am getting the following error. I am learning from the videos/usage code from internet.
Severity Code Description Project File Line Suppression State
Error CS1579 foreach statement cannot operate on variables of type 'HomeDetailsViewModel' because 'HomeDetailsViewModel' does not contain a public instance definition for 'GetEnumerator' EmployeeManagement C:\projects\EmployeeManagement\Views\Home\Details.cshtml
17 Active
Details.cshtml
@model EmployeeManagement.ViewModels.HomeDetailsViewModel
@{ ViewBag.Title = "Employee Details";}
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title></title>
</head>
<body>
<table><thead>
<tr>
<th>ID</th>
<th>Name</th>
<th>Department</th>
</tr>
</thead>
<tbody>
@foreach(var employee in Model)
<tr>
<td>@employee.Id</td>
<td>@employee.Name</td>
<td>@employee.Department</td>
</tr>
}</tbody> </table></body></html>
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
namespace EmployeeManagement.Models
{
public interface IEmployeeRepository
{
Employee GetEmployee(int Id);
IEnumerable<Employee> GetEmployees();
}
}
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
namespace EmployeeManagement.Models
{
public class Employee
{
public int Id { get; set; }
public string Name { get; set; }
public string Email { get; set; }
public string Department { get; set; }
}
}
using EmployeeManagement.Models;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
namespace EmployeeManagement.ViewModels
{
public class HomeDetailsViewModel
{
public Employee Employee { get; set; }
public string PageTitle { get; set; }
}
}