Introduction: In this article i
am going to explain the following:
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.
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.
Controller :
Now over to you:
- What is Asp.Net MVC?
- Asp.Net MVC pattern.
- How MVC works i.e. MVC flow.
- Goals and Advantages of 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.
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."
29 comments
Click here for commentsNice article, it is very useful and easy to understand, thanks a lot
ReplyPlease upload some examples of regarding this topic
Very Nice ,
ReplySaroj Panda
Nice
ReplyThank you.... Nice Article
ReplyYour welcome Chandu Kumar..keep reading and stay connected for more useful updates like this...:)
ReplyThanks Saroj panda for liking my work..keep reading and stay connected for more useful updates like this...:)
ReplyIt 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..:)
Replyi am glad you liked my post..keep reading and stay tuned for more useful updates....
ReplyVery nice article. Thanks a lot Lalit...
Replythank you so much sir,
Replyplz update artical on mvc regularly
Your welcome mandeep and thanks for appreciating my work...
ReplySure Ajay...i will now also focus on MVC..so keep reading..
Replythanks anil kumar yadav..keep reading for more updates..
ReplyHi 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..:)
ReplyVery Nice article...looking forward for some snippets on MVC.
ReplyHello Lalit..Please upload some more articles on MVC covering all aspects .
Replythanks Asif..
ReplyHi Asif..i will upload more article on MVC very soon..stay connected for more updates..
ReplyNice article, it is very useful and easy to understand, thanks a lot.
ReplyPlease provide more example with database . if possible then provide control level description i.e datagrid,dropdown,listview..
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
Replyhttp://www.webcodeexpert.com/2013/11/aspnet-mvc-application-to.html
Nice article, it is very useful and easy to understand, thanks a lot
ReplyYour welcome Gandharv..and thanks for appreciating my article..keep reading..:)
ReplyNice Article ,Please update with MVC articles Regularly
ReplyHi kamesh..thanks for your appreciation and suggestion..i will update more articles on MVC very soon..keep reading..
ReplySoo nice and helpful article.
ReplyHi Naga Suresh..i am glad you found this article helpful..stay connected and keep reading..:)
ReplyReally it's very very helpful .Thnku so much,
ReplyI 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
thanks a lot for your each and every post.
ReplyThanks for your valuable feedback..Stay connected for more useful updates like this..
ReplyIf 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..