How would you sprinkle-in ASP.Net MVC into an existing Web Site Project? [closed]

Well for starters adding MVC to a webforms project is pretty simple, to get the features in VS 2008 for MVC takes a little bit more work (still easy). First you want to be sure you reference the assemblies and are using .Net 3.5. Second you can create a controllers folder and views folder in your current web forms project. You can also create a simple controller with an index action. Then setup/configure the routes in the global.ascx file. You should be set from there. Check here for reference.

However you will only be able to create aspx pages with code behinds (you can delete those and enter the right inheritance class in the markup). To actually “convert” your project type so that you get the goodness of MVC and visual studio (add new view, goto controller, etc) is going to take some playing around with. My best advice is to create a new MVC project in VS 2008 and a new Web App project and compare the .csproj files in plain text. There is a long string value that tells VS the project template.

Believe me this does work. I have done it before on my own legacy projects. I don’t remember how I found the project type “key” besides trial/error/elimination. ASP.Net MVC does play nice in the same project as webforms.

UPDATE: I think you can change to an MVC project type, which is still a web application by using these in the PropertyGroup of the .csproj file. Compare those to what you have and change the one that are differnt, be sure to copy/backup the file.

<ProjectGuid>{B99EC98A-1F09-4245-B00D-5AF985190AA9}</ProjectGuid>
<ProjectTypeGuids>{603c0e0b-db56-11dc-be95-000d561079b0};{349c5851-65df-11da-9384-00065b846f21};{fae04ec0-301f-11d3-bf4b-00c04f79efbc}</ProjectTypeGuids>

Update 2: You wouldn’t affect your project or impact it very much. If you are un easy about it make a backup and play around. If you encounter changes you will always have the backup. I was skeptical at first but was glad I went down the MVC path.

Leave a Comment