Alex Rivera | Logout

Having MVC controllers light and models heavy

Asked 2012-08-17T20:34:23.013
10

I have heard that the controller should be kept light and models heavy.

I am somewhat confused about the best practice on what should be kept in the controller and what should be kept in the model.

In our organization, we use Entity Framework where and put the tables there.

For the controller, we use LINQ and then send the info over to the view.

Kind of confused on what code should be in the Controller and in the Model.

Edit
Report

1 Answer

0

In the classic Model-View-Controller MVC pattern, your Model is essentially a "headless" application, with no UI and is completely UI-agnostics. It offers an API that is the functional core of the application.

The View is the user interface, however you choose to define it (web page? elevator control panel? something else?). A given application might have 1 view or it might have many views.

The Controller (or Controllers — like Views, you might have one to many Controllers for a given application) relays and transforms events, notifications and data between View and Model so as to preclude the Model from needing to know anything that is View-specific.

The idea is to isolate the core application (the Model) from the user interface (the View). From that some things follow:

  • The View is aware of and communicates with both Controller and Model (you're unlikely to try to wire up the View to another Model) and expected for the Controller to be aware of both View and Model.

  • The Controller is aware of and communicates with both View and Model.

  • The Model knows nothing of Controller or View.

Code that performs business logic should be in the Model, not in the Controller.

answered 2012-08-17T21:09:21.553

Your Answer