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.).

If you enjoyed reading this blog, consider subscribing to the RSS feed. You can also subscribe to it by email. You can also follow me on Twitter. Thank you!



You can follow any responses to this entry through the RSS 2.0 feed. You can leave a response, or trackback from your own site.

25 Responses to “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

    Reply
  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.

    Reply
  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.

    Reply
  4. I see. You should then put a dot at the intersection to make it obvious to dummies like me… ;)

    Reply
  5. @Lee – added dots. Done. Thanks for pointing out :)

    Reply
  6. 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.

    Reply
  7.   Derik Whittaker Says:

    @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.

    Reply
  8. @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.

    Reply
  9.   Rafferty Uy Says:

    Nice article, and perfect timing! We were just deciding whether or not to use MVC.

    Reply
  10. @Rafferty – so, which way did you go and why?

    Reply
  11. 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.

    Reply
  12. @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.

    Reply
  13.   Rafferty Uy Says:

    @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?

    Reply
  14. @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.

    Reply
  15. @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.

    Reply
  16. @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.

    Reply
  17. @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 !

    Reply
  18. @pims – exactly :)

    And I love the domain name in your email.

    Reply
  19. “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 )

    Reply
  20. 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.

    Reply
  21. 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.

    Reply




Leave a Reply