Choosing Between WebForms and MVC


Now that Asp.Net is much more mainstream at work, the question is asked time and again as to which one should be used while developing a Web Application. One possible way to answer this question is to do a rudimentary SWOT analysis of both the frameworks.

Following is the SWOT analysis for each:

mvc_swot 

forms_swot

Based on the above, a broad over decision flow can be created as shown in the following picture.

decision

Everything apart, I think there are two major considerations for choosing between the two:

  • Test Driven Development – life would be MUCH easier using MVC while following TDD.
  • Data Driven Application – life would be MUCH easier using WebForms if the application is data heavy.

Of course, there are no rights or wrongs, and every application can be written in both frameworks. In fact, you can even have a hybrid approach, where you can write some part in WebForms and some in MVC (theoretically).

What’s your experience?

Here’s the SWOT analysis in text form:

Asp.Net MVC SWOT

Strengths

  • Provides fine control over rendered HTML.
  • Cleaner generated HTML.
  • Superior separation between UI and code.
  • Easier to unit test.
  • Can support multiple view engines.
  • By default uses RESTful interfaces for URLs – so better SEO.
  • No ViewState (this may also be a weakness).
  • Typical size of page is small.
  • Easy integration with frameworks like JQuery.

Weaknesses

  • Not event driven, so maybe difficult for people who know only Asp.Net Webforms to wrap their minds around it.
  • Third party control library support is not that strong.
  • No ViewState(this is also a strength).

Opportunities

  • Allows for Test Driven Development (TDD) – it is built with TDD in mind, so its much easier to write unit test cases, mock objects, and to intercept the program flow.
  • Allows for reuse of the same models to present different UIs and Interfaces.

Threats

  • Bigger ramp-up and training time required for developers with no or little experience in web application development.

Asp.Net WebForms SWOT

Strengths

  • Provides very good RAD development capabilities.
  • Great designer support in Visual Studio.
  • Ease of development for data-heavy LOB applications.
  • Very rich control libraries and third party vendor support.
  • A familiar event-driven model when compared to Windows Forms development, and so easy for developers to pick up.

Weaknesses

  • UI logic coupled with the code, and thus is hard to separate.
  • Harder to unit test, so difficult to employ TDD.
  • Heavy page sizes due to view state management.

Opportunities

  • Great at creating quick prototypes for business applications. This comes in very handy when trying to show quick Proof of Concepts to clients.

Threats

  • Harder to adopt to various UI views despite the various frameworks available (master pages, Themes, etc.).

39 thoughts on “Choosing Between WebForms and MVC”

  1. Thanks Vaibhav! This clarifies a lot of things for me very quickly. Do you think that something like Oxite (see visitmix.com) resolve some of the drawbacks of MVC? Specifically, I think it might address issues with preferring WebForms over MVC for data-driven apps.

    –Gus

  2. Good article, but your flowchart is flawed. If you notice, there is a double incoming arrow between “Heavy data driven application” and “Need RAD development?” decision nodes. Therefore, it is actually impossible to ever reach these nodes from the initial “Develop Web application” use case.

  3. @Lee – actually, that is not a double arrow. All outgoing arrows have the color of the box they are going out of. There are 4 arrows following the no path after the TDD decision (html control, RAD, Data Driven, Winforms programmin).

    @Gustavo – I have never seen visitmix. I will have to check it out to be able to comment on that.

  4. Very nicely put. I’ve been working on a new project and doing it in both web forms and ASP.NET MVC (sadistic, I know, but it allows me to effectively hedge my bet in case the ASP.NET MVC app doesn’t turn out so great).

    ASP.NET MVC is by no means a silver bullet. A lot of people treat it as the end-all-be-all of web application, but its really only applicable for certain application types (ones that need heavy unit testing and fine-grained control over the HTML). The friendly URLs are a push in my opinion since the routing engine can be supported with standard web forms as well.

    As for Oxite, it’s not a good, or even passable in many people’s eyes, example of an ASP.NET MVC application. There are a slew of blog posts detailing why, mostly from the ALT.NET community.

  5. @Kevin,

    Yes the Alt community has spoke out about oxite, but not because of ‘alt’ issues. But because it was presented as a ‘model mvc’ application that violated EVERY rule of the MVC pattern, not the MVC framework.

  6. @Kevin – are you doing two copies of it? Wow. But yes, that is exactly what I understand MVC to be – one possible framework which is highly suited for some type of web apps.

  7. Personally, I like to go with ASP.Net MVC. The problem is that I think it will take longer to complete the same application if we go with MVC than with WebForms (let me know if you do not agree with this).

    But, we haven’t finalized a decision yet. Part of the decision factor will be how fast our client wants the first version to be out. We’ll try to sell to them how MVC is easier to maintain because of automated testing and separation of UI and business logic… but ultimately, the decision will really depend on them.

  8. @Rafferty – I would like to say that if you are developing a product (long life cycle) which will have many releases over a period of time, and is public facing (many browsers), then MVC might be the way to go. Any extra effort spent coding will pay off in the long run (less regression time, less testing because of better control on views, for example).

    But if it is a one off, internal-to-an-organization, application, then WebForms.

  9. @Vaibhav – I guess you’re right. In our case, the product is internal-to-an-organization who still uses IE6 (soon IE7) as their standard browser. It is also only used by less than 100 people.

    But, the product has a long life cycle. There will be change requests and additional enhancements every 3-6 months. Which is why we are considering MVC for more flexibility and faster tests.

    By the way, why is the WebForms approach better for “Heavy Data Driven Applications?” And what did you mean by heavily data driven?

  10. @Rafferty – the point with heavily data driven refers to pages which have a lot of data grids, form validations, etc.

    While you can do all that in MVC, it just takes much more work to achieve that (as of now) as compared to WebForms. So once again it boils down to effort in the short run.

  11. @Vaibhav jQuery offers some very useful plugins (datagrid, sliders …) that may replace the one provided in webforms. It’s not exactly the same, but close enough. I really think MVC is the way to go, the MVC framework still has to evolve (it’s fairly young afterall) but MS is on the right track. It should also help drawing people from other MVC framework (RoR, Code Igniter …) to the .NET platform. I’ll “never” look at webforms again.

  12. @pims – you are right of course. And MVC makes it much easier to use frameworks such as JQuery.

    The point is that for software development companies (such as mine) the “but close enough” translates to cost which reduced profitability. So at least at this stage in the evolution of Asp.Net, one still needs to consider whether they should look at Web Forms.

    As people get trained, and tools get mature, this may change of course.

  13. @Vaibhav and for a company like mine, it’s more profitable since I’m proficient in Javascript. It’s easier to extend & create plugins, that haven’t made it to Webforms yet ;)

    So all in all, pick whatever suits you best !

  14. “UI logic coupled with the code, and thus is hard to separate. ”

    not agree ,
    furthermore ,i think it more separate then MVC.
    if you know how to implement the 3 tier or more.

    1.
    DL -data layer

    2.
    BL – comunicate with DL only
    ,transfer query to fill bl object

    3.
    code behind layer(aspx.cs) -
    it comunicate with BL and GUI (like a controler)
    e.g. new person oPerson(id);
    lblName.text=oPerson.name;
    ===
    GUI- it is the aspx(no server code here!!)

    and this is the oop way.(much as can in http )

  15. I agree with Ron,
    Webforms is very Unit Testable when you know how to structure a multi tired/layered app.
    And if you choose to the UI layer can be unit tested with implementation of the MVP pattern.

  16. Very nice charts!

    I was surprised during my initial testing of MVC at how fast MVC database pages load and update. It really makes it nice for the users to work with.

  17. The best presentation of both worlds that I have seen. After reading the big differences many times, it’s always nice to see a visual presentation like that.

  18. Somewhat nice article, alot of developers out there going to be pretty upset when they hear they have been prototyping apps the last 7 years. We have built a couple apps in MVC and it has some nice things about it, all this talk of reuseable UI elements is beyond belief, ever heard of an .ascx? If you are blessed with the time to write an application in MVC then that is a big factor, however in the real world, most things need to be done yesterday and WebForms and not as a prototype are the way to go. Every one keeps talking about viewstate, someone should talk about managing it because it is not that bad if you are careful and turn it off when not needed, we are not in the 14.4 32MBRam days. The choice here is easy enough, how much time do you have for a project and does the site require alot of user interaction, if time is short and alot of user interaction, then web forms, if you have time and are mainly diplaying data, then MVC… now if more people would get silverlight… then just do that, no more WC3 to worry about, awesome UI capabilities and windows app speed once the xap is loaded….

    ah but the battle will rage on.

    1. I agree. I have never known a business to just give me so much time. As per all of the WebForms issues I hear about, they are rare for me. We have one developer finishing up on a project where he used MVC 2.0 and the project will end up 2 months behind schedule and way over on hours. The last project I did came in 25% of the time that a consultant firm quoted us at and I did it in WebForms.

      Another point, is finding people to maintain your programs. If everyone knows MVC than the point is moot. Unfortunately, the MVC population is much smaller than the WebForms population.

      I’m also hoping Silverlight will get out there faster. Silverlight is a lot of fun.

  19. Hi Vaibhav,
    Very nice article. Makes it very clear about MVC and web forms.

    Interesting to checkout the following.
    http://navigationnerddinner.codeplex.com/

    It looks like a combination of MVC and web forms. and i feel its best of both worlds when using this navigation framework.
    We can still use web forms and benefit from MVC features like UnitTesting.

  20. In my opinion, the question is becoming blurred with a lot of the cool features of MVC making their way into Webforms. ASP.NET 4.0 added URL Routing, reduced ViewState, and greater control of the HTML mark-up produced by many ASP.NET controls, now the next version of Webforms will incorporate many more MVC features into Webforms. http://bit.ly/dNhBd8

  21. Golden, thanks for posting this thorough analysis. It is still true today as the day it was written. I’ll stick with web forms thank you.

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>