I am about to create a ViewModel to pass some data to a View. So if the application structure is convention based. Where are the ViewModel definitions to be kept. I could create a new directory called ViewModels, but what is the RIGHT way.
views:
167answers:
5I don't think there's a widely accepted convention for this.
I have 'ViewModels' folder too.
I keep my view models in the Models folder because my data models reside in a separate assembly.
We've reluctantly settled on a models folder as well even though our views and controllers are in separate assemblies. We painted ourselves into the corner since we also use some of our WCF client-side DTOs directly in the view but those WCF client-side DTOs are generated in our controllers assembly. I blogged about our dilemma in some greater detail.
I keep all VM in a separate assembly (dll), so you can run tests easily against them - even outside ASP.NET scope...
You shouldn't have a ViewModel in an ASP.NET MVC application. You're getting mixed up with WPF's MVVM pattern, which is a different beast (same genus, tho).
The convention in ASP.NET MVC is to have your controllers under the Controllers directory at the root of your solution. Check out the ASP.NET MVC website template.
Now, if you're talking about the Models, the same applies as above (Models folder, check the template). These are conventions and not hard rules, so depending on how anal you are you can put them pretty much wherever it makes sense.