5

Possible Duplicate:
ASP.NET MVC alongside Web Forms in the same web app?

I am kinda new to .NET applications, I have a web forms application that I am working on and I am about to start the development of new pages, I am trying to make the new pages with the ASP.NET MVC, but I am not beeing able to make the pages hit the controllers. First i added the library references added the routes on the global.asax but not sure what else is missing, can someone help me out?

thx.

0

4 Answers 4

6

Reading between the lines I gather you are trying to add MVC pages to your existing ASP.NET Webforms Webapplication?

If that is the case then you probably need some MVC specific config. settings. Easiest way is to create a new MVC web app and then merge the config settings.

Furthermore if you are doing a hybrid project I'd recommend giving Scott Hanselmann's post on the topic a read.

1
  • I second this opinion on comparing Web.config ASP.NET MVC settings with the existing ones and considering a careful merge. Feb 21, 2009 at 12:23
2

There's a more step-by-step description of adding MVC to a WebForms Application at these links:

You might also want to add the ProjectTypeGuid to the project file with a text editor ({603c0e0b-db56-11dc-be95-000d561079b0} is used to designate to Visual Studio to use the MVC extensions.)

    <ProjectTypeGuids>{603c0e0b-db56-11dc-be95-000d561079b0};{349c5851-65df-11da-9384-00065b846f21};{fae04ec0-301f-11d3-bf4b-00c04f79efbc}</ProjectTypeGuids>

The links above also don't fully cover the system.webserver area of web.config that needs to be configured.

0
0

Scott Hanselman released a "totally unsupported" Nuget package that adds MVC 3 features to an existing Web Forms project. It also works on my PC (ha ha) and I've used it on several projects.

http://nuget.org/List/Packages/AddMvc3ToWebForms

He blogged about it here:

http://www.hanselman.com/blog/CreatingANuGetPackageIn7EasyStepsPlusUsingNuGetToIntegrateASPNETMVC3IntoExistingWebFormsApplications.aspx

One newb tip: this package will configure your MVC routes in /App_Start/RegisterMvc3Routes.cs

0

I've spent a lot of time over the past few months on this. Here are my observations.

The good/easy - Getting Webforms to call into MVC controllers - It was remarkably easy to stand up a new MVC3 project and drop Webforms pages into it. - I was able to move my <pages><controls></controls></pages> section into the /pages directory in a new web.config there

The dirty/difficult

  • Regarding the GUID

    • Please note that the GUID has to be added at the front of the line for some reason... everytime I tried it failed. Until I stumbled on a post that insisted it be the before the others.
    • also I don't know what the difference is but I have a different GUID working... {E53F8FEA-EAE0-44A6-8774-FFD645390401}
  • getting the landing page to be Webforms caused ALL kinds of snags.

  • getting jQuery intellisense to play nicely with T4MVC

this is what I did to address that

@if (System.Diagnostics.Debugger.IsAttached)
    { 
    <script src="../../Scripts/Mvc3/jquery-1.7-vsdoc.js" type="text/javascript"></script> @* intellisense! *@
     @Html.RelativeJavascript(Links.Scripts.Mvc3.jquery_1_7_js)
     @Html.RelativeJavascript(Links.Scripts.Mvc3.jquery_unobtrusive_ajax_js)
    }
    else
    {
        @Html.RelativeJavascript(Links.Scripts.Mvc3.jquery_1_7_min_js) 
        @Html.RelativeJavascript(Links.Scripts.Mvc3.jquery_unobtrusive_ajax_min_js)  
    }

Recommendations:

  • Use T4MVC in ALL cases even if you are pure webforms. The elimination of magic strings for static content (.js,.css, images, specifying templates) is outstanding.