I'm having trouble understanding how to group data in ViewModel, fill it and pass it to the view. I use Entity Framework with a code-first approach.
My domain model is:
public class Product
{
public int ProductId { get; set; }
[DisplayName("Name of the product")]
public string ProductName { get; set; }
[DisplayName("Descritpion of the product")]
public string ProductDescription { get; set; }
[DisplayName("Price of the product")]
public decimal ProductPrice { get; set; }
public int EAN { get; set; }
public int CategoryId { get; set; }
public virtual Category Categories { get; set; }
}
I also have my view model:
public class ProductIndexGroup
{
public int EAN { get; set; }
public string ProductName { get; set; }
public int Quantity { get; set; }
}
What I am aiming for is fairly simple, but as a newbie in ASP.NET MVC, I'm having trouble achieving it. I would like to group data using my view model and display it in view like this:
EAN Product Name Quantity
-----------------------------------
12354 Product1 5
98765 Product2 2
Any help is greatly appreciated.