Comparison between ASP.NET Web Forms and ASP.NET MVC Development

ASP.NET Frameworks

When facing a decision to choose between ASP.NET Web Forms or ASP.NET MVC it is important to know that neither technology is meant to replace the other. Although ASP.NET MVC was released at a later date, it is not designed to be a successor to ASP.NET Web Forms. When making this decision it is very important that one learns and understands the differences between these two frameworks. Certain applications might be better suited for one, while other applications might fit better with the other. There are pros and cons with both Web Forms and ASP.NET MVC, and the following page and accompanying demo should reveal some from both camps.

For Microsoft’s point of view on the subject, please refer to this MSDN Magazine article.

Quick Glance

WebForms MVC
Ease of use Separation of concerns
ScriptManager/UpdatePanel * Ease of testability
State Tracking * No ViewState, no page life cycle
Maturity Total control over HTML
Control life cycle Controller to Model to View
Strong 3rd party component market Accessibility

* In discussions that are pro-MVC these can be seen as negatives as well.

Although this is more of a myth than reality, for a long time the lack of ASP.NET MVC developer productivity tools has also been considered a disadvantage for choosing the platform. For example Telerik released a suite built from the ground up according to the principles of ASP.NET MVC as soon as the framework was released by Microsoft. Telerik now offers both an ASP.NET AJAX and ASP.NET MVC UI component suites to give developers more options when choosing the technology for their applications. RadControls for ASP.NET AJAX offers more than 70 high-performing, rich UI controls, and the Kendo UI for ASP.NET MVC offers more than 40 lightweight, HTML5-powered extensions for building rich cross-platform web, data visualization and mobile applications.


ASP.NET AJAX vs ASP.NET MVC – Projects


ASP.NET AJAX – File Structure

WebFroms file structure
Figure 1.1

Looking at the basic file structure of an ASP.NET AJAX we can see that there is no need to place web pages in various folders, an .aspx file can be placed directly in the root of the web application. There are some ASP.NET specific folders, such as App_Data, which tend to serve as a location to add specific types of files. However, all of the web pages could, in theory, be placed immediately under the project root folder.

Read more

ASP.NET MVC – File Structure

MVC file structure
Figure 1.3

Taking a look at Figure 1.3 we can see that in the ASP.NET MVC file structure is a bit different than that of the ASP.NET AJAX one. Something that pops up immediately is the folder structure, specifically “Models”, “Views” and “Controllers”. These are what make up the MVC acronym – Model-View-Controller. Expanding the folders also reveals that there is no WebForm and code-behind structure.

Read more



ASP.NET AJAX vs ASP.NET MVC – Demo Application

In the demo application there are a couple of demos highlighting some of the main differences between using the Telerik RadControls for ASP.NET AJAX and the Telerik Extensions for ASP.NET MVC. The components that are highlighted are the Menu, TreeView, Editor and Grid.

Download Source Code

The Basics Demo

The first demo simply shows a common scenario where a button is used to update a label. In the ASP.NET AJAX case we take use of an UpdatePanel which wraps the label and the button. The button has a click event which is subscribed to and in the code-behind the label is references and its Text property is modified.

Taking a look at the ASP.NET MVC equivalent we see that the controller, via an ActionResult, is in charge of updating the label’s content. A dynamic variable found in MVC 3’s ViewBag (ViewData for MVC 2 can be used) is used to bind to the label, and any changes to this variable will be reflected in the label.


Site Navigation Demo

Menu

Both the RadMenu for ASP.NET AJAX and the Menu for ASP.NET MVC have a similar simple structure. The Menus themselves have an item collection which defines the root items of the Menu.  Each one of the Menu items can in turn have its own item collection, which is seen as the sub-items of that particular item.

 


Content Editing Demo

Editor

The RadEditor for ASP.NET AJAX has two possible approaches when configuring what tools should be included with the control. You can, as seen in the demo, define the tools collection declaratively in the markup of the Editor by creating various tool groups and defining tools within them. The other implementation is to use a ToolsFile.xml file which can be used to define the tools to be used outside of the markup of the RadEditor.

The Editor for ASP.NET MVC approaches the tools configuration similarly as the first implementation above. There is a tools collection which takes use of the fluent-API of the Telerik Extensions which allows you to chain several tools that can be used with the Editor.

 


Data Binding/Editing Demo

Iteration planning

The RadGrid for ASP.NET AJAX uses the OnNeedDataSource event when utilizing a more advanced style of binding than just a declarative approach. This event gets fired every time the RadGrid is in need of data (paging, sorting, filtering etc.). Additionally, when manually handling the insert, update and delete operations with the RadGrid one needs to subscribe to either the OnItemCommand event, and use if-statements to find out which operation is occurring, or use the OnInsertCommand, OnUpdateCommand and OnDeleteCommand events.

With the Grid for ASP.NET MVC we simply use the controller to send the data that we need over to our Grid component. We also define the names of ActionResults for each of the CRUD operations, including which controller they are to be found in. One difference between the RadGrid and this Grid is that in the Insert, Update and Delete functions we take use of the GridRouteValues() extension method, which returns route values defining the Grid state. Some of the items included in these route values are current page, sort and filter expressions.