My picture of an MVC-WebForms marriage

Like it or not, WebForms is not going away.  Fortune 50 companies use it for their public facing, mission critical websites, and I can’t really see many of these folks tossing away years of work simply because MVC is the new shiny.  Talking with some industry folks, I see a lot of fear/misunderstanding around the MVC/WebForms story going forward.

One thing that Jeffrey at Headspring has convinced me of recently is that there should be a convergence of these two models at some point in the future.  On a recent large project, we’ve had areas where it just made sense to use WebForms.  For us, it was a 3rd party reporting control.  Making the transition there was tough, however, as many things I counted on in MVC just weren’t there any more.  However, recent strides in ASP.NET 4.0 have eliminated many of the existing headaches.

My vision of an MVC-WebForms marriage is one of a seamless harmony, one where I can go back and forth between MVC and WebForms without much issue between the two.  So what is needed to make this marriage last?

Model Binding/Strongly-Typed pages

One of the big pains going from MVC to WebForms is the lack of model binding.  I don’t like poking into controls to get values, nor do I enjoy poking into the querystring/forms collections to manually munge dictionaries.

In addition to model binding would be pages where I could strongly-type the Page class, so that I didn’t have to manually pull junk out of controls.  I could see this done in a variety of ways, whether it’s an overloaded Page_Load event, a different Page base class or whatever.

Shared HtmlHelpers and MasterPages

I’d like to easily generate links from MVC to WebForms, and vice-versa.  Additionally, I don’t want to create a new Master Page for WebForms pages.  I haven’t tried to mix both, but it would be nice to be able to share a common template for both sets of pages.  If I get HtmlHelpers, then I can easily use Url.Action, Html.ActionLink and so on.

Routing

This is already in ASP.NET 4.0, nothing else needed here.  Since I can create routes for WebForms, I can use the route-based URL generators in MVC land to generate a link from an MVC to WebForms page.  Of course, I can always hard-code the .ASPX URL.

There are still situations in every-day work that WebForms is the right way to go.  I like MVC as a pattern more than the presenter/front controller of WebForms, and that’s a conscious choice I make.  But for those wanting to mix technologies, it’s still a little ways off before these can both live together in harmony, if only for those times when I absolutely must use both.

Related Articles:

Post Footer automatically generated by Add Post Footer Plugin for wordpress.

About Jimmy Bogard

I'm a technical architect with Headspring in Austin, TX. I focus on DDD, distributed systems, and any other acronym-centric design/architecture/methodology. I created AutoMapper and am a co-author of the ASP.NET MVC in Action books.
This entry was posted in ASP.NET, ASP.NET MVC. Bookmark the permalink. Follow any comments here with the RSS feed for this post.
  • http://mrdustpan.blogspot.com/ MrDustpan

    After working on a couple of MVC projects, I’m currently back on a WebForms project. I find myself thinking that WebForms is “not that bad”, but I totally agree that things like model binding and strongly typed pages would be great to have.

  • http://www.openprojects.co.uk Dom Finn

    We have been using MVC and I love it but I do like some of the pre built Web Forms controls and wish we didn’t have to make our own / JQuery them up each time.

  • http://http:://bugsquash.blogspot.com Mauricio Scheffer

    I’ve used WebForms MasterPages in MVC pages in the same app, it (mostly) works after a couple of hacks like this one: http://bugsquash.blogspot.com/2009/02/aspnet-mvc-postback-support.html

  • http://www.corebvba.be Tom Janssens

    I have no idea if this would be straightforward to do, but couldn’t you use the mvc modelbinder in a webforms app ?? The modelbinder just binds to a httpcontext, so it might be doable…

  • http://www.marriagerecords.org/resources/ State Marriage Records

    Lately I’ve been reading again lot of discussions going on about whether WebForm is a much wiser choice for developers, NET MVC brings productivity away because it forces you to learn another framework or because it makes you think more about pattern, or name-your-other-rather-random-opinion.