Los Techies : Blogs about software and anything tech!

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.

Kick It on DotNetKicks.com
Posted Jan 18 2010, 08:25 PM by bogardj
Filed under: ,

Comments

Twitter Trackbacks for My picture of an MVC-WebForms marriage - Jimmy Bogard - Los Techies : Blogs about software and anything tech! [lostechies.com] on Topsy.com wrote Twitter Trackbacks for My picture of an MVC-WebForms marriage - Jimmy Bogard - Los Techies : Blogs about software and anything tech! [lostechies.com] on Topsy.com
on 01-19-2010 4:05 AM

Pingback from  Twitter Trackbacks for                 My picture of an MVC-WebForms marriage - Jimmy Bogard - Los Techies : Blogs about software and anything tech!         [lostechies.com]        on Topsy.com

MrDustpan wrote re: My picture of an MVC-WebForms marriage
on 01-19-2010 10:25 AM

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.

Cadred (dotNET) wrote .NET Pulse 1/19/10
on 01-19-2010 12:20 PM

.NET Pulse 1/19/10

Dom Finn wrote re: My picture of an MVC-WebForms marriage
on 01-20-2010 4:28 AM

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.

Mauricio Scheffer wrote re: My picture of an MVC-WebForms marriage
on 01-20-2010 5:15 PM

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

ASP.NET MVC Archived Blog Posts, Page 1 wrote ASP.NET MVC Archived Blog Posts, Page 1
on 01-25-2010 12:12 AM

Pingback from  ASP.NET MVC Archived Blog Posts, Page 1

Tom Janssens wrote re: My picture of an MVC-WebForms marriage
on 01-25-2010 4:09 AM

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

State Marriage Records wrote re: My picture of an MVC-WebForms marriage
on 01-27-2010 5:13 AM

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.

Add a Comment

(required)  
(optional)
(required)  
Remember Me?

Enter the numbers above:
Copyright Los Techies 2008, 2009. All rights reserved.
Powered by Community Server (Commercial Edition), by Telligent Systems