Get Help:Ask a Question in our Forums|Report a Bug|More Help Resources
Last post May 25, 2012 11:31 PM by CPrakash82
May 25, 2012 09:19 PM|LINK
I've developed my first few pages in MVC and I am re-considering how I have organized my code. We will have multiple pages (Views) that I want to group in one controller. So we may have a Finance controller, a HumanResources controller, an Admin controller,
etc. Finance would then have several Views in the Views/Finance folder and so on. I see most of the code being placed in models and stored procedures (on the database). The controllers would be lightweight basically just taking a request, gathering the
data from the model, and then returning it to the View. Is it normal that most of the code lies in the models and stored procedures, or how do others organize their MVC projects?
May 25, 2012 11:26 PM|LINK
It all depends on the project type and scope. Usually i dont want to mix a lot of business logic in my model classes. I would keep them as simple POCO ( plain old class object)s to represent my domain model. Basically, I would seperate my domain entities
and data access into a seperate project. So i will have my project structure like this
UI Project : My basic MVC stuff : My Controllers , Views , ViewModels, Scripts , Images etc...
Business Entities : My POCO's for domain models. I would use these to generate my database if i am goind to do codefirst approach ( Created database from your entities ) .
DataAccess : This project will have the Data Access code. It can be typical ADO.NET with stored proc or Entity framework or any other ORMs. I will add a reference to my Businesss Entities project here so that i can use them here.
In my UI Prokect, I will add references to my Entities and DataAccess project.
If my project has view model , I would add a mapping/Service layer as well to map my domain model objects to the ViewModels.
And YES. I like to keep my controllers clean. I usually call the methods in my service layer to get he data / objects which calls my service data access layer.
May 25, 2012 11:31 PM|LINK
Please see the below project designed in MVC and they have good architecture in place.
ASP.NET Storefront application
Excellent blog on controller responsibility.