Upgrade Application from Asp.Net MVC2 to MVC3

Upgrade Application from Asp.Net MVC2 to MVC3

It’s been a much long after MVC3 is been released & now it is much stable. So while working on a project, I need to upgrade my ASP.Net MVC 2 project to MVC 3.

ASP.Net MVC 3 can be installed side by side ASP.Net MVC 2 on you PC, which gives you flexibility in choosing when to upgrade an MVC2 application to MVC3. It is been very easy to upgrade the project to MVC3. We just need to follow following steps

  • Remove all references of System.Web.Mvc from each project in solution.
  • Now add a reference for System.Web.Mvc 3.0 to each of the project in the solution.
  • Also add a reference of System.Web.Helpers 2.0 to web project.
  • Also add a reference of System.Web.WebPages 2.0 to web project.
  • Go to views folder & open the Web.Config file & replace Version = 2.0.0.0 with version 3.0.0.0
  • Also add following code  to this Web.Config

  • Open the root Web.Config file & replace all references of “System.Web.Mvc 2.0.0.0” with “System.Web.Mvc 3.0.0.0”.
  • Now in appSettings add following keys

  • Now we need to make sure our system.web->pages->namespaces tag contains following entries

  • In the system.web->compilation->assemblies we should have following entries

  • Finally under the configuration -> runtime section put following code

  • And lastly add following javascript on your master pages, you need to add this javascript file to Scripts folder.  We need to get this file from any asp.net mvc3 project & paste it in the scripts folder. Also it is recommended you replace the old javascript files such as MicrosoftAjax.js, MicrosoftMvcAjax.js & MicrosoftMvcValidation.js.

Yuhu……………! Here we are. Now just compile & run your code. Now it will run on MVC3. Also we need to make sure we are targeting .net Framework 4.0 while upgrading the MVC2 application to MVC3.

Also there is a tool available to upgrade the MVC2 to MVC3. Here is a link to the tool

http://weblogs.asp.net/leftslipper/archive/2010/07/28/migrating-asp-net-mvc-2-applications-to-asp-net-mvc-3-preview-1.aspx

Cheers…..!

You can find the source code here.