ASP.NET MVC - Strongly typed view model, where does it belong?

asp.net-mvc, model-view-controller, viewmodel

Solution

It should go in the "Models" directory of the web app. ViewModels are by definition specific to one or more views and therefore belong in the web app, not the core.

You could define them in the controller that uses them, but this doesn't scale. Same with defining the class in the view code. Even though one-class-per-file means more files, its easier to find code and easier to maintain.

I'll often create a subfolder for each controller, so I end up with things like Web.Models.Foo.BarViewModel.

Problem

I'm trying to create a strongly typed view model as John Sheehan suggests here. Where should it go? I can make arguments to myself for Model, View, and Controller.

Original source

Related problems