views:

327

answers:

3

Hi,

In asp/net MVC, the project is divided into Models, Views and Controllers. Fine so far.

Say I have a Class 'person', which the people controller populates with data, using the person model.

Where is it best to put my person.cs class? In the controllers or the models folder? What do you do?

Thanks

Frank

+3  A: 

I would consider Person a model and put it in the Models folder. This is where I keep my view models. Business models are normally kept in a separate data project -- I like my data layer to be self-contained so I can use it in other projects if I want. You might want to consider creating separate class libraries for other types of classes -- extension methods, helpers, etc. that don't fit into the category of controllers or models.

tvanfosson
Thank you very much - I wasn't sure so thought I'd ask.
+2  A: 

I'd create another class library project in the solution, define my classes and then reference my library in my ASP.Net MVC application.

WebApp Solution
|-MyMVCProject
  |-Models
  |-Controllers
  |-Views
|-MyMVCProject.Domain (you'd put your models here)
  |-Person.cs
|-MyMVCProject.Services (you'd put entity services here)
scottm
Now this makes sense...
A: 

Currently working at rather large project, I have my classes divided into different class library projects which are named Repository (for data access interfaces and business data classes), Utils (for utility classes) and DataAccess (repository interfaces implementations). Under those I have them divided in subdirectories (or should I say namespaces) and then use Resharper to enforce those namespaces.

mare