What is Asp.Net MVC? Its work flow,goals and advantages

Introduction:  In this article i am going to explain the following:
  • What is Asp.Net MVC?
  • Asp.Net MVC pattern.
  • How MVC works i.e. MVC flow.
  • Goals and Advantages of MVC.
In another article i explained the Asp.Net MVC 4 application to Create,Read,Update,Delete and Search functionality using Razor view engine and Entity Framework and  Differences between Asp.Net Webforms and Asp.Net MVC 

Description: MVC stands for model-view-controller. It is methodology or architectural pattern or framework or standard software design pattern that splits/separates an application into three main components i.e. Model, View and Controller  for developing web application  that are easy to maintain, well architected and highly testable in a different manner than the traditional Asp.net web development. The MVC framework is defined in the System.Web.Mvc assembly.
Figure : MVC Pattern

MVC framework is light-weight framework having some existing Asp.net features like master pages, user controls, Globalization, Caching, membership/roles/profiles, validations and security features.

MVC helps us to create web applications that separate the different components/aspects of the application i.e. Model (Business Logic), View (User Interface) and Controller (Input Logic).  This separation helps us in managing complexity of the project because developer can focus on implementing one component at a time, thus facilitates parallel development e.g. One developer can focus on the view , another developer can work on business logic and third developer can focus on implementing controller logic.

It is clear from the figure: MVC pattern above that both the view and the controller depend on the model. But the model is independent of the view and the controller both. This is the key benefits of the separation. This separation allows the model to be built and tested independent of the visual presentation (UI).

Some points about the three components of MVC pattern are described as:

Model :
  • Model represents a set of classes that represent the application's data and use validation logic to enforce business rules for how the data can be changed and manipulated.
  • The Model is the part of the application that handles the logic for the application data.
  • Often model objects retrieve and store model state in database.
  • It consists of application data, business rules, logic, and functions.
  • The model notifies its associated views and controllers whenever there has been a change in its state. This notification allows the views to reproduce updated output, and the controllers to change the available set of commands.
  • The Model is responsible for providing all the required business logic and validation to the view.
  • In MVC application the models are stored in the Models folder by default.

View :
  • The Views in Asp.Net MVC is responsible for overall look and feel and for transforming the models into UI (User Interface) and for displaying the data that is received from the controller as the result.
  • Most often the views are created from the model data.
  • Views are the template files that the application uses to dynamically generate HTML responses.
  • A view requests information from the model that it needs for generating an output representation to the user.
  • The view is responsible for displaying all or a portion of the data to the end user.
  • In MVC application the views are stored in the Views folder by default.

Controller :
  • Controller represents the classes that respond to incoming browser requests, retrieve appropriate model data based on that and validates the input, and then specifies appropriate view templates that return a response to the browser.
  • The responsibility of the controller is to control the application logic and acts as the mediator between the View and the Model. The Controller receives input from users via the View and then it processes the user's data with the help of Model and passes the results back to the View.
  • The controller actually handles and responds to user input and interaction. For example, the controller handles query-string values, and passes these values to the model, which in turn might use these values to query the database.
  • In MVC application, the controllers are stored in the Controllers folder by default. 
So Controller receives all user requests for the application and then works with the Model to prepare any data required to View. The View then uses the data prepared by the Controller to generate a final presentable response.

MVC Flow :
  • All end user requests are directed to controller
  • The controller depending on the request determines which model to select/load. The controller loads the associated model and attaches the model with the appropriate view.
  • The final view is then attached with the model data and sent as a response to the end user on the browser to be rendered.

Advantages and goals of MVC pattern:
  • MVC makes it easier to manage complexity by dividing an application into the model, view, and the controller. So very clean separation of concerns (SOC).
  • It is really easy to edit or change some part of your project that makes less development cost and maintenance cost. So MVC pattern reduces development time and simplifies overall maintenance.
  • Support for existing Asp.net features like master pages, user controls, Globalization, Caching, membership/roles/profiles, validations and security features.
  • MVC does not use view state or server-based forms. So best suitable for having full control over the behavior of an application.
  • Facilitates easy unit testing.
  • It provides better support for test-driven development (TDD) and Enhanced testability.
  • Improve the structure of software.
  • Each component can be easily tested because it is loosely coupled.
  • Minimize logic needed in views.
  • Clean URLs and HTML thus more control over URLs and HTML. So better for Search Engine Optimization (SEO) also.
  • Easier parallel development because the separation provided by MVC helps us in managing complexity of the project because developer can focus on implementing one component at a time e.g. One developer can focus on the view , another developer can work on business logic and third developer can focus on implementing controller logic.
  • Facilitates easy to customize applications.
  • Easy integration with JavaScript frameworks.
  • MVC does not support view state and also there is no post back events. So improves application performance.

Now over to you:
" I hope you have got what is Model-View-Controller in Asp.Net MVC and If you like my work; you can appreciate by leaving your comments, hitting Facebook like button, following on Google+, Twitter, Linked in and Pinterest, stumbling my posts on stumble upon and subscribing for receiving free updates directly to your inbox . Stay tuned and stay connected for more technical updates."

Previous
Next Post »

29 comments

Click here for comments
Anonymous
admin
November 01, 2013 ×

Nice article, it is very useful and easy to understand, thanks a lot
Please upload some examples of regarding this topic

Reply
avatar
Anonymous
admin
November 01, 2013 ×

Very Nice ,

Saroj Panda

Reply
avatar
A1785
admin
November 01, 2013 ×

Thank you.... Nice Article

Reply
avatar
November 01, 2013 ×

Your welcome Chandu Kumar..keep reading and stay connected for more useful updates like this...:)

Reply
avatar
November 01, 2013 ×

Thanks Saroj panda for liking my work..keep reading and stay connected for more useful updates like this...:)

Reply
avatar
November 01, 2013 ×

It is always nice to hear that my article helped anyone..I will upload articles on MVC very soon..so stay connected for more useful updates..:)

Reply
avatar
November 01, 2013 ×

i am glad you liked my post..keep reading and stay tuned for more useful updates....

Reply
avatar
mandeep
admin
November 02, 2013 ×

Very nice article. Thanks a lot Lalit...

Reply
avatar
Unknown
admin
November 02, 2013 ×

thank you so much sir,
plz update artical on mvc regularly

Reply
avatar
November 02, 2013 ×

Your welcome mandeep and thanks for appreciating my work...

Reply
avatar
November 02, 2013 ×

Sure Ajay...i will now also focus on MVC..so keep reading..

Reply
avatar
November 05, 2013 ×

thanks anil kumar yadav..keep reading for more updates..

Reply
avatar
November 07, 2013 ×

Hi srinivas..i am working on MVC article having save,update,edit,update,delete and search functionality and will publish that by this monday..so keep reading for more useful updates on MVC..:)

Reply
avatar
Unknown
admin
November 08, 2013 ×

Very Nice article...looking forward for some snippets on MVC.

Reply
avatar
Unknown
admin
November 08, 2013 ×

Hello Lalit..Please upload some more articles on MVC covering all aspects .

Reply
avatar
November 09, 2013 ×

Hi Asif..i will upload more article on MVC very soon..stay connected for more updates..

Reply
avatar
Unknown
admin
November 12, 2013 ×

Nice article, it is very useful and easy to understand, thanks a lot.

Please provide more example with database . if possible then provide control level description i.e datagrid,dropdown,listview..

Reply
avatar
November 13, 2013 ×

Thanks Viresh..have you checked the article: Asp.Net MVC 4 application to Create,Read,Update,Delete and Search functionality using Razor view engine and Entity Framework
http://www.webcodeexpert.com/2013/11/aspnet-mvc-application-to.html

Reply
avatar
Gandharv
admin
December 19, 2013 ×

Nice article, it is very useful and easy to understand, thanks a lot

Reply
avatar
December 20, 2013 ×

Your welcome Gandharv..and thanks for appreciating my article..keep reading..:)

Reply
avatar
kamesh
admin
January 31, 2014 ×

Nice Article ,Please update with MVC articles Regularly

Reply
avatar
February 01, 2014 ×

Hi kamesh..thanks for your appreciation and suggestion..i will update more articles on MVC very soon..keep reading..

Reply
avatar
Naga Suresh
admin
February 01, 2014 ×

Soo nice and helpful article.

Reply
avatar
February 02, 2014 ×

Hi Naga Suresh..i am glad you found this article helpful..stay connected and keep reading..:)

Reply
avatar
Anonymous
admin
April 10, 2014 ×

Really it's very very helpful .Thnku so much,
I want to learn Asp.net so
Can u tel m how I stdy it tht i can complete asp.net within 1month with avrag understanding as I am a fresher..please reply me sir

Reply
avatar
Anonymous
admin
January 17, 2015 ×

thanks a lot for your each and every post.

Reply
avatar
January 22, 2015 ×

Thanks for your valuable feedback..Stay connected for more useful updates like this..

Reply
avatar

If you have any question about any post, Feel free to ask.You can simply drop a comment below post or contact via Contact Us form. Your feedback and suggestions will be highly appreciated. Also try to leave comments from your account not from the anonymous account so that i can respond to you easily..