The big picture
Now that we’ve seen the details of the M, the V, and the C, let’s try to get an understanding of the big picture by looking at how they all work together. The diagram below illustrates a standard request cycle in an MVC application.
A typical MVC request cycle
The process begins when a user takes an action on a web page – submitting a form that adds a new blog post, for example. The request is sent to the blog controller, which extracts the data submitted via the HTTP POST request and sends a message to the blog model to save a new post with this data.
MVC INTRO-DOT.NET
The model checks the data against its validation rules. Assuming it passes validation, the model stores the data for this new post in the database and tells the controller it was successful. The controller then sets a variable for the view indicating success.
Finally, the view displays this message to the user back on the web page, and they know their new blog post has been successfully created. If, for some reason, validation of the data failed, the model would alert the controller of any errors, which would set a variable containing these errors for the view. The view would then present the original form along with the error messages for any fields that didn’t validate.
Though there is a lot to take in when first learning MVC, it’s really not as complicated as it sounds. Just remember that the model is the data, the view is the user interface, and the controller is the mediator. Even if not using a web framework that uses MVC design, the principles of separating presentation and business logic in an application are very helpful in creating clean, compact, reusable code that will be fun and easy to work with. Once the concepts of MVC are mastered, learning a new framework is a breeze.


RSS
Delicious
Facebook
GooglePlus
Myspace
Twitter
Youtube