random techno tidbits
Organizing view models in ASP.NET MVC (Part 2 of 3)
This is the second part of Organizing view models in ASP.NET MVC (see Part 1).
So, designing classes for your view models inevitably brings up some new concerns, like how should the Layout view models be implemented (master pages in terms of WebForms view engine).
From my experience, you should create an abstract class like SharedLayoutViewModel with all of the data properties required by your _Lauout.cshtml. Then, make all of the view models of views that use this layout inherit this class. You can use MVC Result filters to fill this model with data in a single place of your app, or, like I do, override the OnResultExecuting method in the common base class for your controllers, and fill it there.
To make your view models easy to find, organize them in a similar fashion as you do for views. I prefer putting all the view models in a single namespace (though in different project directories) and having full name as its class name like ProductsCreateViewModel (if you’re using ReSharper, set NamespaceProvider = False). This way I avoid need of explicit namespace reference in views and controllers. So my final layout looks like this:

In the next part I’ll give a sample of a simple form implemented using the described approach.