How can i iterate foreach without IEnumerable
Repo.cs
public Employee GetEmployee(int id)
{
var x = (from n in db.Employee
where n.Emp_Id==id
select n);
return x.FirstOrDefault();
}
Controller
public ActionResult GetEmpById(int id)
{
var x = ObjRepo.GetEmployee(id);
return View(x);
}
Index.cshtml
Here I'm gettin Error as The model item passed into the dictionary is of type 'Mvc_Application.Models.Employee', but this dictionary requires a model item of type 'System.Collections.Generic.IEnumerable`1[Mvc_Application.Models.Employee]'.
@model IEnumerable<Mvc_Application.Models.Employee>
<table class="table">
<tr>
<th>
@Html.DisplayNameFor(model => model.Email)
</th>
</tr>
@foreach (var item in Model) {
<tr>
<td>
@Html.DisplayFor(modelItem => item.Email)
</td>
</tr>
}
</table>