I’m new to using both Entity Framework and MVC, but not new to programming. I am working with a large table and I want to return selected columns of the query back to the view and list them. The basic query is as follows:
public class EmployeeController : Controller
{
private ADPEntities db = new ADPEntities();
// GET: /Employee/
public ActionResult Index()
{
var tblEmployeeADPs = db.tblEmployeeADPs
.Where(p => p.Status == "Active")
.Select(p => new UserViewModel.USerViewModelADP
{
Status = p.Status,
FirstName = p.FirstName,
LastName = p.LastName,
SSN = p.SSN
});
return View(tblEmployeeADPs.ToList());
}
}
I created a basic C# class to strongly type the results (i.e. UserViewModel
) and I still get an error:
The model item passed into the dictionary is of type 'System.Collections.Generic.List1[UserViewModel.USerViewModelADP]', but this dictionary requires a model item of type 'System.Collections.Generic.IEnumerable1[DysonADPTest.Models.tblEmployeeADP]'.
when I execute the page.
I’m not sure what I’m missing, as I was sure that (cobbling what I’ve read) that this would be the answer.