This entry is part 4 of 4 in the series ASP.NET - WebForms versus MVC

Conclusion

If your application relies on rich user controls (either 3rd party or your own in-house controls), WebForms may be the best option. The reports of WebForms being un-testable are greatly exaggerated – and one can easily write unit tests around webforms (for e.g. – using NUnitForms).

The greatest driving factor for doing MVC is Test Driven Development (TDD) – and while MVC does make it a piece of cake to write comprehensive unit tests, it is not entirely difficult to do the same in the webform world. Some other reasons to adopt MVC would be:

  • To support platforms with disparate display types – e.g. Mobile and Desktop and Web. Using heavy winforms/webforms controls here would mean a complete re-write of the presentation layer to support mobile displays. With MVC, the view is cleanly separated out – making it easy to write a ‘ mobile view ‘ and a ‘desktop view’. This is perhaps the biggest motivator to use mvc ( more so than testability – since UI testability can be achieved with WINFORMS/webforms as well.

  • To build SEO based URLs

  • To have more control over the generated HTML – allowing easier integration with jQuery and other javascript frameworks.

  • Open Source Technology

The choice depends on the nature of your application. Personally, the types of applications I work with are all heavy on user controls – and WebForms lends itself to building such apps. Being a TDD fanatic as well, I resort to writing NUnitForms tests for my webforms. Regarding some of the other shortcomings of webforms, there are simple workarounds for each of them (e.g. ViewState can be disabled,  ClientIds can be controlled in ASP.NET 4.0 onwards). If I build an app using just MVC and have to revisit it later to add a sophisticated UI control (such as a datagrid etc.) to the application, I may have a lot of work ahead of me. On the flip side, if I already have a WebForms app, there is little that can be thrown at it that will call for a complete overhaul of the existing architecture.

Anuj holds professional certifications in Google Cloud, AWS as well as certifications in Docker and App Performance Tools such as New Relic. He specializes in Cloud Security, Data Encryption and Container Technologies.

Initial Consultation

Anuj Varma – who has written posts on Anuj Varma, Hands-On Technology Architect, Clean Air Activist.


Series NavigationBuilding Rapid, Testable Web-Forms–Comparing the MVC Framework with ASP.NET WebForms