I’m little confused with how a ViewModel should be structured.
A generic example would be Customer with a list of Orders.
Should there be 3 viewmodels?
CustomerViewModel – list of fields that applies to this …
OrdersViewModel – list of field that applies to this…
public class CustomerOrdersViewModel
{
public CustomerViewModel Customer{ get; set; }
public OrdersViewModel Orders { get; set; }
}
To display a view with Customer details at the top as Master Details then show a grid of Orders that relates to the Customer.
I am using CustomerOrdersViewModel.
Is this the correct approach?
alphabeatsco
A generic example would be Customer with a list of Orders.
Should there be 3 viewmodels?
f you have one View, then it will be one ViewModel.
My objective is to create a page which has the Customer Details at the top.
Below is a list in a Kendo Grid with all its Orders.
How should my viewmodel structure look like?
Your plan looks good? no issue.
in other way, You can have a property Orders of type
OrdersViewModel directly to the CustomerViewModel. Setting the value to this
Order property is depending on what you want to display on view ( Only customer detail or customer with orders)
;