Reputation: 108491
I've been poking around this site and I've seen a few post about how to "migrate" to MVC from Web Forms... but as a single developer working on a complex Web Forms app I simply don't have the time to to a full migration. What I want to do is add all new content using MVC, and migrate older content over as I have time (and/or have too). I see a lot of benefits for my environment with MVC.
Another thing to note is that all Web Forms .aspx are living in the root directory at the moment, and I have some old school URL Rewriting setup (like: "/id/123/s/whatever/PageName.aspx" -> "/PageName.aspx?id=123&s=whatever") that might complicate things.
There also is a templating system that uses MasterPages that might pose a challenge. Are those handled differently with MVC?
At this point I haven't added anything MVC related to my application.
So, how do I go about, step by step, adding my first Model, View and Controller to an existing Web Forms app?
Edit:
I also found this article which details most of what I needed to do: http://blogs.imeta.co.uk/MGodfrey/archive/2009/03/31/663.aspx
Unfortunately it's still not working. I think because I have a Web Site and not a Web Application. (In other words my classes are living in the App_Code directory).
Upvotes: 8
Views: 4840
Reputation: 183
For anyone who stumbles on this in the future: You can do this with just a few clicks in visual studio 2013 Pro.
http://www.asp.net/mvc/mvc5 -Scroll down to the bottom under the heading “ASP.NET Scaffolding, ” and in 3rd to last paragraph:
“To add MVC scaffolding to a Web Forms project, add a New Scaffolded Item and select MVC 5 Dependencies in the dialog window. There are two options for scaffolding MVC; Minimal and Full. If you select Minimal, only the NuGet packages and references for ASP.NET MVC are added to your project. If you select the Full option, the Minimal dependencies are added, as well as the required content files for an MVC project.”
Upvotes: 5
Reputation: 7424
Heres a pdf that might help you out. It is pretty in depth and it should show you enough info to get started implementing mvc into your web forms application. It shows how to incorporate mvc into web forms and vice versa.
Upvotes: 2
Reputation: 20357
Scott Hanselman has some pretty good articles on mixing MVC and webforms. One article that seems similar to what you're looking for is here.
And another article for adding MVC to existing apps with step-by-step instructions is here.
The second article pretty much walks you through CH12 of ASP.NET MVC 1.0 by the guys who wrote ASP.NET MVC. Of course it's from a different book, but the content is the same.
Upvotes: 6