views:

153

answers:

5

The default ASP.NET MVC project sets up a "Models" directory that I don't know that I've ever used in the handful of MVC projects I've worked on. Normally, I have a separate 'library' project that stores business logic classes.

Now I'm curious: Am I missing something big by not taking advantage of the default ASP.NET "Models" directory? Is there some built-in functionality that uses this nicely?

+2  A: 

The folder itself doesn't have "special" functionality, but simply is a suggestion as to where to keep your model classes (that is, your data classes, e.g. ORM generated (LINQ)).

Example classes are Customer, Address, Order etc. that model the underlying data entities.

Alex
+8  A: 

I typically use this directory for my view models. Domain models live in a separate project/assembly, but the view models are kept with the web project in the Models directory. Adding models to this directory automatically sets them up in the *.Models namespace.

tvanfosson
+1  A: 

Since I generally keep my models in a separate project/assembly I use the Models folder to store UI specific classes, like if I have a View that displays both a Widget and a Foosit, I just wrap them up in a WidgetFoositContext object.

public class WidgetFoositContext {
  public Widget Widget { get; }
  public Foosit Foosit { get; }
}
swilliams
+1  A: 

I use the models directory to store compositions of my business objects. If you are in the product controller I will create a ProductViewData class to store the product itself as well as a list recommended products and a list of reviews on that the product.

I prefer to keep my business objects pretty simple and the models directory is where I can knit together different forms of data I will need in my view.

nbirkes
+5  A: 

You're not missing anything. In my opinion, the only reason the folder is created is simply because it's ASP.NET MVC and they needed folders for the "M", "V", and "C". By default, ASP.NET MVC doesn't tell you how to implement the "M", so it just gives you a blank folder as a suggestion on where to put your model classes. You're free to delete this folder and put your model where you'd like.

Kevin Pang