Saturday, October 8, 2011

Advantages and Disadvantages of ASP.NET Webforms Vs ASP.NET MVC


These are my thoughts according to what I have studied about ASP.NET MVC vs ASP.NET WebForms, its very necessary to know the basic differences between starting the journey of learning MVC and know what the end result will look like in an enterprise application done in MVC.

It might be more time, Completely agree, but at the end you have more control of everything, in the other hand WebForms do most of the hard work for you.

Here are some basic questions I needed to answer my self before starting my first project with MVC, and the community answers I got.


1) MVC has no viewstate? So how can I save data in the current page? This seems a very big disadvantage.
Why do you want to save things in the page? That's what databases are supposed to do. Save data. In the page you simply use a hidden field allowing you to refetch the data from wherever it was initially stored. And for data that can change you have form input fields, so it will be there.

2) Webform says that provide an extensive event model with lots of controls, Doesnt MVC support controls and events as a normal webform?
No, MVC doesn't support controls and events. It supports models, controllers and views.
Lets suppose I am an expert on both? why would I choose one or the other? So far the only good thing about MVC in my opinion is testability, becase Rapid Application Development in webforms win in so many ways to MVC.
That's a subjective question for which there is no objective answer. The answer I can give you is: it will depend on the context. I agree that RAD wins in WebForms, but what you have to remember is that it is not the development of the application that costs most. It's its support and maintenance. So if your application is written rapidly you will ship it quickly indeed but with the time if you don't properly architect it with extensibility in mind this quick application development turns slowly into a nightmare, until the day comes where you simply have to rewrite it because it costs you so much to continue to support it.
Now talking about the RazonEngine, it seems like going back to the old ASP, you cant use server side controls? how is this an advantage for me?
You have total control of the markup, your pages are no longer polluted with useless ViewStates, and at last your markup validates. If you want to reuse some view portions in ASP.NET MVC you could use partial views.
ASP.NET MVC applications hand you back control over the way your application works and it conforms to the 'native' model of HTTP/HTML.
WebForms is an abstraction of web application programming; envisaged to ease the transition for the Visual Basic programmers who were the primary target for .NET when it was launched. The trouble is, it's a 'leaky abstraction'. It uses 'tricks' under the cover to make it appear to operate in a way that is simple for those used to VB's event-based model, such as viewstate and postbacks. The trouble with this (and all those 'leaky abstractions') is that while the basic stuff is easy, once you try to do something that doesn't fit within the abstraction, it gets dramatically more complicated.
If your applications are trivial and the WebForms abstraction consistently works for you, feel free to stick with it. Microsoft have been considerate enough to continue to support it.
But if your applications are at all sophisticated or complex (as more and more are these days), I'd suggest looking at MVC with an open mind.

No comments: