I have a very simple ViewModel (ProductViewModel)
public class ProductViewModel
{
public int ProductID { get; set; }
public int CategoryID { get; set; }
public string ProductName { get; set; }
public string CategoryName { get; set; }
}
In my controller I'm grabbing a specific Product
var product = _context.Products
.Select(p => new ViewModels.ProductViewModel
{
CategoryID = p.Category.CategoryID,
ProductID = p.ProductID,
ProductName = p.ProductName,
CategoryName = p.Category.CategoryName
}).Where(p => p.ProductID == id);
return View(product);
In my view I'm defining the model as
@model MvcApplication1.ViewModels.ProductViewModel
However, I'm getting this error:
The model item passed into the dictionary is of type 'System.Data.Entity.Infrastructure.DbQuery`1[MvcApplication1.ViewModels.ProductViewModel]', but this dictionary requires a model item of type 'MvcApplication1.ViewModels.ProductViewModel'.
I'm not sure why it's throwing that error since I am passing ProductViewModel into the view...At least is looks like I am. Any guidance would be appreciated
Thanks!