I have these 3 classes:
public class Product
{
public int ProductId { get; set; }
public int ClassId { get; set; }
public string Name { get; set; }
public virtual Class Class { get; set; }
}
public class Partner
{
public int PartnerId { get; set; }
public int ClassId { get; set; }
public string Name { get; set; }
public virtual Class Class { get; set; }
}
public class Price
{
public int PriceId { get; set; }
public int ClassId { get; set; }
public int ProductId { get; set; }
public int PartnerId { get; set; }
public float Cost { get; set; }
}
and I have 3 lists of data:
List<Product> products; List<Partner> partners; List<Price> prices;
How can I show partners in top row, products in left column and price (if it is available for each partner and product) in cells of table in MVC View?
As always I would start by designing a view model that will reflect the requirements of the view:
and then I will populate this view model in the controller action from our domain models and pass it to the view:
and finally I will have a corresponding strongly typed view to the view model: