I’m using asp.net mvc 2 and I’m not sure howto structure the models and viewmodels. In the nerddinner there is only 1 of each.
Shall I have only 1 viewmodel of each entity (?) and then have 1 model for each form-modifing viewpage? So that viewmodel contains like all it ever would need, like: PagedFoo FooClass …, FooClass, Foowithbunnies, FooClassStats… ?
/M
The way I view this is that (Domain) Model objects represent your business entities. Anything the business requirements dictate go there.
View Models are there to make the view as simple as it can be. So all the display logic, data massaging etc., goes there.
And yes, there will be times where one will seep into the other (Hey, you got your View Model/Peanut Butter in my Domain Model/Chocolate!), and it’s OK.
But your goal should be to keep them as separate and clean as possible. This seems to lead to the most re-usable and easy to maintain code.