Click here to Skip to main content
Click here to Skip to main content

Ignore ASP.NET MVC at Your Own Peril: Lessons Learned from the Trenches

Still messing with View State? See why web developers are flocking to ASP.NET MVC. This article uses code examples and a side-by-side comparison with Web Forms

Editorial Note

This article is in the Product Showcase section for our sponsors at CodeProject. These reviews are intended to provide you with information on products and services that we consider useful and of value to developers.

Introduction

As users, we enjoy the experience offered by certain web sites more than others. Some of our favorite sites include Google maps and basecamphq.com. What does it take to provide such a user experience? This document examines aspects of interest when attempting such a task using the two web-development frameworks from Microsoft: Web Forms and ASP.NET MVC.[1] Please note: this is a very short version of the original white paper. The full text with much more technical detail is available here -> Read the full white paper.

Ajax

Ajax allowed for the selective refresh of sections of a Web page. With Web Forms, even when the user interface refresh was selective, the actual cycle of server-side post-back and server lifecycle events was required to be complete since the server-side abstraction model depended on it. This is not the most optimal way to implement Ajax.

With ASP.NET MVC there is no real abstraction of the details. HTTP is a stateless protocol. Ajax calls are trivial to implement. They perform exactly as advertised and can be selectively processed on the server.

Separation of Concerns: User Interface code and Business Logic

The Model-View-Controller pattern is a very simple pattern that advocates the clear separation of responsibilities between the model (data), controller (logic & orchestration) and the view (presentation). It has been observed to help produce more maintainable, structured applications.

A key issue with Web Forms is that the controller and view (and at times even the model) are implemented together in the Web Forms page (or server-side control). This tied key parts of the application’s logic into the view, making the application hard to maintain.

ASP.NET MVC takes the separation between the view and the controller very seriously. The controller orchestrates interaction between the model and the view. There is no coupling between the view and the model or the view and the controller.

jQuery

Web Forms applications can use jQuery, but not in a very optimal manner. Web Forms controls act as self-contained units and produce an extensive amount of intricate markup making it hard to target such elements from jQuery.

With ASP.NET MVC, developers have complete control over the markup. This makes it the norm to have HTML that is jQuery friendly.

Unobtrusive JavaScript

Unobtrusive JavaScript helps tackle browser inconsistencies and makes it easier to manage the view.

It is certainly possible for Web Forms controls to be written with Unobtrusive JavaScript principles but this is not the case with the vast majority of controls.

Controls written for the ASP.NET MVC framework (typically) respect this model and attach behavior on the client-side, keeping the behavior clearly separate from the content and presentation.

Performance

The ASP.NET MVC Framework allows for very lightweight markup. Any state maintained by applications is targeted, and usually a small fraction of ViewState on similar Web Forms pages.

Consider the following traffic reports from an HTTP traffic diagnostics utility – Fiddler tracking two similar applications.

  WEB FORMS ASP.NET MVC
UI
Data sent 17.5 KB 1.5 KB
Data received 50.1 KB 1.4

Browser Compatibility

Internet Explorer no longer commands the 90+% market share that it used to, making it very important to ensure that Web applications are browser agnostic.

Web Forms Controls are mostly written using vendor-specific JavaScript libraries that offer varied support across browsers.

ASP.NET MVC applications and controls typically implement their client-side functionality using jQuery. This leads to solid browser compatibility.

Testing

Solid and easy testing of business logic and data access is considered to be critical to the development of maintainable Web applications.

Web Forms applications are very hard to test. The view often contains business logic and presentation, making it very hard to test.

ASP.NET MVC makes testing easy, even fun. All of the core components of ASP.NET MVC are designed to easily run from any unit testing container.

SEO

Friendly URLs fare well with search engines since these URLs allow the search engine to correlate terms that appear in the URL with other aspects being considered to determine ranking.

It is possible to formulate friendly URLs with Web Forms. This is not, however, the norm.

ASP.NET MVC treats action methods as page content and completely hides physical page details. The routing system is very elegant and tightly woven into the framework, allowing for the crafting of friendly URLs.

User Interfaces

Web Forms has a wide variety of controls available from Microsoft and numerous third-party vendors. They make it easy to add a rich and polished user interface to your applications.

It is a common misconception that ASP.NET MVC does not offer a rich set of user-interface elements. Microsoft provides a limited set of helpers out of the box, but a solid third-party control market is taking root. Every major component vendor has a currently shipping suite of controls or has one in the works.

For example, Syncfusion offers rich menus, editors, grids, charts, an Outlook-like scheduler, gauges and much more.

image006.jpgimage007.jpg

With Microsoft Visual Studio 2010, ASP.NET MVC is tightly integrated into the IDE. Visual Studio’s excellent scaffolding support for ASP.NET MVC allows for a very productive experience. It takes only a few clicks to create a fully functional, strongly typed view for an action method. ASP.NET MVC’s convention-over-configuration approach makes it very easy to get started. You can certainly build a great looking UI with minimal effort when working with ASP.NET MVC.

Conclusion

With ASP.NET MVC you can truly venture to build websites that offer extremely compelling experiences.

Action Items

  • Consider the ASP.NET MVC 2 platform for your Web development needs
  • Download a suite of ASP.NET MVC controls from your favorite vendor and put them to the test
  • Beat your competition to the punch and be the first in your industry to switch to ASP.NET MVC!

There is simply no excuse to be toying with ViewState anymore!

[1] Note: This article is excerpted from the full white paper, which can be downloaded here.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

About the Author

Syncfusion
Syncfusion
United States United States
Founded by industry experts in 2001, Syncfusion, Inc. provides the broadest range of enterprise-class software components and tools for the Microsoft .NET platform. With Syncfusion, developers can move beyond simply coding applications to delivering real business innovation—the elegant user interfaces, business intelligence dashboards, and sophisticated reporting that today's business users need, in the formats they demand. Our award-winning .NET components and controls are designed to meet your evolving development needs, whether you're working in Windows Forms, WPF, ASP.NET, ASP.NET MVC, or Silverlight. Syncfusion can be reached at info@syncfusion.com, +1 919.481.1974, toll-free in the U.S. at 1.888.9DOTNET or through its Web site, www.syncfusion.com.
Group type: Organisation

2 members


Comments and Discussions

 
GeneralNice article Pinmembermyker1-Aug-10 4:54 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

| Advertise | Privacy | Mobile
Web01 | 2.8.140709.1 | Last Updated 7 Jun 2010
Article Copyright 2010 by Syncfusion
Everything else Copyright © CodeProject, 1999-2014
Terms of Service
Layout: fixed | fluid