混合WebForms / ASP.NET MVC [重复]

时间:2021-06-30 03:22:23

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

可能重复:ASP.NET MVC和Web Forms在同一个Web应用程序中?

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?

我是.NET应用程序的新手,我有一个我正在处理的Web表单应用程序,我即将开始新页面的开发,我正在尝试使用ASP.NET MVC创建新页面,但我是不能使页面击中控制器。首先我添加了库引用添加了global.asax上的路由但不确定还缺少什么,有人可以帮助我吗?

thx.

4 个解决方案

#1


6  

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

在我收集的行之间读取您正在尝试将MVC页面添加到现有的ASP.NET Webforms Web应用程序中?

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.

如果是这种情况,那么您可能需要一些MVC特定的配置。设置。最简单的方法是创建一个新的MVC Web应用程序,然后合并配置设置。

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

此外,如果你正在做一个混合项目,我建议给Scott Hanselmann关于这个主题的帖子。

#2


2  

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

有关在这些链接上将MVC添加到WebForms应用程序的更多分步说明:

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.)

您可能还希望使用文本编辑器将ProjectTypeGuid添加到项目文件中({603c0e0b-db56-11dc-be95-000d561079b0}用于指定Visual Studio使用MVC扩展。)

    <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.

上面的链接也没有完全覆盖需要配置的web.config的system.webserver区域。

#3


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.

Scott Hanselman发布了一个“完全不受支持的”Nuget包,它将MVC 3功能添加到现有的Web Forms项目中。它也适用于我的电脑(哈哈),我在几个项目中使用过它。

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

一个新提示:此包将在/App_Start/RegisterMvc3Routes.cs中配置您的MVC路由

#4


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

好/易 - 让Webforms调用MVC控制器 - 站起来一个新的MVC3项目并将Webforms页面放入其中非常容易。 - 我能够将 部分移动到新的web.config中的/ pages目录中

The dirty/difficult

  • Regarding the GUID

    关于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.
    • 请注意,由于某种原因,必须在行的前面添加GUID ...每次我尝试失败时。直到我偶然发现一个坚持它在其他人之前的帖子。

    • also I don't know what the difference is but I have a different GUID working... {E53F8FEA-EAE0-44A6-8774-FFD645390401}
    • 我也不知道有什么不同但我有一个不同的GUID工作... {E53F8FEA-EAE0-44A6-8774-FFD645390401}

  • getting the landing page to be Webforms caused ALL kinds of snags.

    使着陆页成为Webforms会导致各种障碍。

  • getting jQuery intellisense to play nicely with T4MVC
  • 让jQuery intellisense与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.
    • and if you have any part of your build process compiling views then you get compile-time safety on any of those links.
    • 如果您的构建过程中有任何部分编译视图,那么您可以在任何这些链接上获得编译时安全性。

  • 即使您是纯webforms,也可以在所有情况下使用T4MVC。消除静态内容(.js,.css,图像,指定模板)的魔术字符串非常出色。如果您的构建过程中有任何部分编译视图,那么您可以在任何这些链接上获得编译时安全性。

#1


6  

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

在我收集的行之间读取您正在尝试将MVC页面添加到现有的ASP.NET Webforms Web应用程序中?

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.

如果是这种情况,那么您可能需要一些MVC特定的配置。设置。最简单的方法是创建一个新的MVC Web应用程序,然后合并配置设置。

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

此外,如果你正在做一个混合项目,我建议给Scott Hanselmann关于这个主题的帖子。

#2


2  

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

有关在这些链接上将MVC添加到WebForms应用程序的更多分步说明:

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.)

您可能还希望使用文本编辑器将ProjectTypeGuid添加到项目文件中({603c0e0b-db56-11dc-be95-000d561079b0}用于指定Visual Studio使用MVC扩展。)

    <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.

上面的链接也没有完全覆盖需要配置的web.config的system.webserver区域。

#3


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.

Scott Hanselman发布了一个“完全不受支持的”Nuget包,它将MVC 3功能添加到现有的Web Forms项目中。它也适用于我的电脑(哈哈),我在几个项目中使用过它。

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

一个新提示:此包将在/App_Start/RegisterMvc3Routes.cs中配置您的MVC路由

#4


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

好/易 - 让Webforms调用MVC控制器 - 站起来一个新的MVC3项目并将Webforms页面放入其中非常容易。 - 我能够将 部分移动到新的web.config中的/ pages目录中

The dirty/difficult

  • Regarding the GUID

    关于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.
    • 请注意,由于某种原因,必须在行的前面添加GUID ...每次我尝试失败时。直到我偶然发现一个坚持它在其他人之前的帖子。

    • also I don't know what the difference is but I have a different GUID working... {E53F8FEA-EAE0-44A6-8774-FFD645390401}
    • 我也不知道有什么不同但我有一个不同的GUID工作... {E53F8FEA-EAE0-44A6-8774-FFD645390401}

  • getting the landing page to be Webforms caused ALL kinds of snags.

    使着陆页成为Webforms会导致各种障碍。

  • getting jQuery intellisense to play nicely with T4MVC
  • 让jQuery intellisense与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.
    • and if you have any part of your build process compiling views then you get compile-time safety on any of those links.
    • 如果您的构建过程中有任何部分编译视图,那么您可以在任何这些链接上获得编译时安全性。

  • 即使您是纯webforms,也可以在所有情况下使用T4MVC。消除静态内容(.js,.css,图像,指定模板)的魔术字符串非常出色。如果您的构建过程中有任何部分编译视图,那么您可以在任何这些链接上获得编译时安全性。