Description: What is MVC. Best Dot Net Training
MVC stands for Model – View – Controller.
What is MVC. Best Dot Net Training
- It is architecture for developing interactive applications where there would be a user interaction involved and event handling would occur.
What is the role of Model, View and Controller?
Model: It manages data basically state of the application in memory. There is no fixed size or shape of model objects since what we intend to hold in memory in one application may not be the same as that in other application. It includes all of an application’s validation logic, business logic and data access logic. For example, an Employee object (Model) might retrieve information from a database, operate on it, validate it and then write updated information back to an Employee table in the database.
View: It contains logic for rendering Graphical Representation / HTML output. Typically it creates UI with data from Model. An example would be an edit view of a Products table that displays text boxes, drop-down lists, and check boxes based on the current state of a Products object.
Controller: It contains control flow logic. It is the one which interacts with both models and views to control the flow of application execution. The controller handles and responds to user input and interaction by creating and passing the model to view. A controller can send commands to the model to update the model’s state.
What is ASP.NET MVC Framework?
A Framework is a collection of classes which provide an abstraction of a particular concept. Framework classes are
re-usable since a Framework is like a Semi-complete application which has to be extended and made complete
for developing a specific application.
Our code fits into the Framework through extension points.
- Every Web Application is interactive by nature and hence is a potential candidate is applying MVC
- .ASP.NET MVC is an alternative framework to ASP.NET WebForm framework for developing Web-based
applications using ASP.NET Framework.
Understanding MVC in context of ASP.NET?
What is a Model?
1. MVC model is basically a C# or VB.NET class
2. A model is accessible by both controller and view
3. A model can be used to pass data from Controller to View
4. A view can use the model to display data on the page (HTML output).
What is a View?
1. A view is a CSHTML page without having a code behind file.
2. All page specific HTML generation and formatting can be done inside view.
3. One can use Inline code (server tags ) to develop dynamic pages.
4. A request to view can be made only from a controller’s action method.
What is a Controller?
1. The controller is basically a C# or VB.NET class which inherits System.Web.Mvc.Controller
2. The controller is a heart of the entire MVC architecture.
3. Inside Controller’s class action methods can be implemented which are responsible for responding to
browser OR calling views.
4. The controller can access and use model class to pass data to views.
Advantages of an MVC-Based Web Application?
Its lightweight because it does not use view state or server-based forms or server controls.
- It makes it easier to manage complexity by dividing an application into the model, the view, and the
- Separating the view from the rest of the application logic enables changing of view (technology) in future
without affecting the rest of the application. For example, you might have views in Silverlight or HTML 5.
- Each developer based on his expertise can work on different parts of the application without stepping on
each other toes. For example, one developer can work on the view, a second developer can work on the
controller logic, and a third developer can focus on the business logic in the model.
- RESTful / User-friendly Url’s and this enables SEO.
- It doesn’t have to rename of ids as in WebForm framework.
- It provides better support for test-driven development (TDD). This is because we can focus on one aspect at a time i.e. we can focus on view without worrying about business logic.
- It’s created to support pattern-based software development.
Get Complete MVC online training tutorial by MCT