I have a collection of items. Here’s my view model:
public class MyViewModel
{
public IEnumerable<MyClass> MyCollection { get; set; }
}
public class MyClass
{
public string VendorName { get; set; }
public decimal Amount { get; set; }
public decimal Tax { get; set; }
}
So my collection has about 200 rows. Multiple rows can have the same vendor name, so there’s 5 different vendor names in my collection.
In the view that I’m passing my view model to, I’d like to display the name of each vendor, and under each vendor I want to display a grid of Amount and Tax for that vendor name.
I assume I need to do this within my view, but I’m not exactly sure how to do it.
I’d prefer to let the view model closely accommodate the view and do as little data manipulation in the view as possible. After all, it is not the view’s responsibility to shape data, just to expose them to the user. So I would use
so you can build the UI elements from the vendor names and their details in just one pass.