Search This Blog

Wednesday, September 14, 2011

ASP.NET Webforms to ASP.NET MVC - Approach

I won't reinvent the wheel in this post as your friend and mine Rajesh Pillai wrote up an awesome step-by-step approach to taking an ASP.NET Webforms project and migrating it to ASP.NET MVC one workflow at a time. 

His post can be found here.  If you also use Microsoft's Ajax Toolkit, there are a couple of things to point out.  First of all, make sure you watch the order in which your handlers are defined.  One side-effect I encountered was the 'case of the missing $sys' in which case MS ajax javascript was being served up through the axd route. 

Second, if you are also a webforms spring.net-enabled site, you'll want to either define your own MVC Controller Factory and declare it in global asax on or use Spring.NET's MVC Application.  In our case, we chose the former approach primarily to minimize impact and have more control over the factory. 

Finally, don't throw away your existing site and try to do the changeover Big Bang.  Instead, carefully choose the workflows in the site you want to convert and convert them one at a time.  Your challenge, if you are unfamiliar with Ajax, is to take those update panels out and replace them javascript that uses an Ajax library (in our case JQuery) to provide the same behaviors. 

A couple of additional SNAFUs I ran into while going through this exercise:
1) Forgetting to add the web.config to the Views folder.  If you create a VS2008 ASP.NET MVC 2 project, you'll notice a web.config is created in the Views folder.  Among other things, this web.config adds essential page filters and parsers which allow for the use of the Html extension when writing up the markup.  Without these, you will not have the correct state in your aspx page with which to make use of them.

2) Controllers marked as Content and not as Compile
This threw me for a loop for a good hour.  I lost all intellisense and like most of the other Microsoft folks out there, felt quite naked and vulnerable.  Check your properties window and make sure the controller class is defined with 'compile'.  It's that simple.

I'll be posting more as we start to transition the site over to MVC v2 framework. 

No comments:

Post a Comment