Introduction to ASP.NET MVC?
ASP.Net MVC is an open-source software provided by Microsoft. It is a web development framework that integrates the features of MVC (Model-View-Controller) architecture to the existing ASP.NET platform.
Why ASP.NET MVC?
It is a framework that Microsoft has created for building web applications. The MVC framework simply builds on the top ASP.NET. When you are building a web application with ASP.NET MVC, there will be no illusion of state, there will not be such things like as a page load and no page cycle at all.
It makes web forms very successful, Microsoft creates ASP.NET MVC to increase the performance.
In a web application, there are some parameters that describe the performance:-
- Response time issues
- The problem of Unit Testing
- HTML customization
- Reusability of code-behind class
ASP.NET MVC excels from all of the above parameters.
Versions of MVC
Till now, 5 versions of MVC were released by Microsoft:
- This version was released on Mar 13, 2009.
- It runs on .NET 3.5 and with Microsoft visual studio 2008.
- MVC pattern architecture with web form engine.
- The main feature includes HTML & UNIT Testing, Routing, etc.
- This version was released on Mar 10, 2010.
- It runs on .NET 3.5,4.0 and with Microsoft visual studio 2008.
- It includes a feature like template helpers, UI helpers with automatic scaffolding & customizable templates.
- It supports Data Annotations.
- It was released on Jan 13, 2011.
- It runs on .NET 4.0 and with Microsoft visual studio 2010.
- It has features like Razor view engine, Global filters.
- It was released on Aug 2012.
- It runs on .NET 4.0, 4.5 and with visual studio 2010 & visual studio 2012.
- It enhanced the default project templates.
- It has features like Mobile project template using JQuery mobile, bundling, minifications, etc.
- This version was released on Oct 17, 2013.
- It runs on .NET 4.5,4.5.1 and with visual studio 2012 & visual OneASP.NET
- Its feature is Attribute based routing.
Features Of MVC:-
- It is easy and has frictionless testability.
- A new way of presentation for ASP.NET
- It supports existing ASP.NET features.
- Clear separation of logic: Model, View, Controller
- It is a Test-driven development framework.
- It also supports parallel development.
- Model: - It is responsible for maintaining application data and business logic.
- View: - It displays the data on the User interface. It is completely HTML which determines how the UI will look like.
- Controller: - It is a set of class which handles the communication with the user, overall application flow. It handles the user's request and provides a response to it.
Idea behind MVC
It has a component named View
which is responsible for providing User Interface. The view communicates with the model and that model contains the data which is required by the view. Views do not have complex logic inside them.
In a web application, a view might not have much code associated with it. It only has HTML that contains the information about where to take the piece of data from the model and put them at the correct places inside the HTML template that you have built in the view.
The controller organizes everything. When an HTTP request arrives for an MVC application That request handled by the controller, and it's up to the controller to talk to either database or the file system.
Microsoft provides the free version of Visual studio which contains SQL server also. You can download it on your system from the following link:
Web Forms vs. MVC
- Model:-NET web forms follow event-driven development model while ASP.NET MVC uses the MVC pattern based development model.
- Used since:- web forms have been used around since 2002 while MVC was released in 2009.
- Support for view state:- web forms support view state for support management at the client site. This makes page heavy while MVC doesn’t support view state.
- URL type:- Web forms have file-based URLs that means file name exists in the URLs and they must exist physically. While MVC has route based URLs that means they are redirected to controllers and actions.
- Code Reusability:- Web forms offers user controls for Code Reusability. MVC has offered partial views for code reusability.
- Control for HTML:- web forms has less control over rendered HTML. While MVC has full control over HTML.
- TDD support:- web forms have weak and custom TDD. While MVC encourages and includes TDD.
- Consistent look and feels:- web forms have master pages for a consistent look while MVC has layouts for a consistent look.
Advantages of ASP.NET MVC
- NET MVC allows us to replace any component of the application.
- It provide better support for test driven development.
- In ASP.NET complex applications are easy to manage because of the division of Model, View, and Controllers.
- MVC supports SEO and REST friendly URL.
- It also supports third-party view engine.
- NET MVC does not support view state and server-based forms this gives full control on developers hand to control application behavior.
Disadvantages of ASP.NET MVC
- NET MVC sites require more time to develop than ASP.net applications.
- It is difficult to learn. It requires in-depth knowledge of the MVC pattern.
- It is quite complicated to implement so that it is not a good option for the small level application.
- It can be complex to understand the flow of an application.
- Every time we have to run the program to see its original design.
Things recommended while using ASP.NET MVC
- In the case of large and complex code, create a separate assembly for the MODEL to avoid any undesirable situation.
- The MODEL should only consist of business logic, session maintenance, validation part, and data logic part.
- The other division part like views and controller must not contain any business logic, session maintenance.
- The controller should be only responsible for preparing and render the view, calling model, etc.
- Use only specific view engine to create HTML markup from your view because of it a combination of HTML and programming code.
If you are going to develop a new application then definitely go with ASP.NET MVC because it will give you the flexibility that you need to start as well as also helpful in future development. It also supports AJAX, CSS, Angular JS, JQuery, and other latest technologies. By using it, you can also take the benefits like more control over HTML, support of TDD, Build in support of SEO URLs, etc. It allows us to create highly testable and loosely coupled applications with Test Driven Development (TDD) and Separation of Concern (SOC).