你将如何撒,在ASP.Net MVC到现有的网站项目? [英] How would you sprinkle-in ASP.Net MVC into an existing Web Site Project?

查看:101
本文介绍了你将如何撒,在ASP.Net MVC到现有的网站项目?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个传统的(哈哈)的ASP.Net Web表单的网站项目在Visual Studio 2008 SP1中,我想逐步介绍一些MVC功能之中。

I have a legacy (haha) ASP.Net Webforms Web Site Project in Visual Studio 2008 SP1, that I would like to gradually introduce some MVC functionality into.

大部分时间我可以如何ASP.Net MVC与整合的WebForms查找信息似乎假定使用了 Web应用程序项目。然而,这似乎是不可能找到有关如何与ASP.Net MVC功能改造现有ASP.net网站项目信息。

Most of the information I can locate on how to integrate ASP.Net MVC with WebForms seems to assume the use of a Web Application Project. However, it seems impossible to find information about how to retrofit an existing ASP.net Web Site Project with the ASP.Net MVC features.

我查看<一个href=\"http://www.hanselman.com/blog/PlugInHybridsASPNETWebFormsAndASPMVCAndASPNETDynamicDataSideBySide.aspx\">Scott Hanselman的帖子和第13章他即将出版的新书中,这两个假设 Web应用程序项目的类型。

I've reviewed Scott Hanselman's post and Chapter 13 of his upcoming book, both of which assume the Web Application Project type.

这可能吗?有没有人有一个如何做这个?

Is this possible? Does anyone have a how-to on this?

推荐答案

那么对于初学者加入MVC到web表单的项目是pretty简单,让在VS 2008中的功能的MVC需要更多一点的工作(仍然简单)。首先,你要确定您引用组件和使用的是.NET 3.5。其次,你可以创建在当前Web窗体项目中的控制器文件夹和视图文件夹。你还可以创建一个索引操作简单的控制器。然后设置/配置在global.ascx文件的路由。你应该从那里进行设置。检查<一href=\"http://www.chadmyers.com/Blog/archive/2007/11/30/asp.net-webforms-and-mvc-in-the-same-project.aspx\">here以供参考。

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.

然而,你将只能创建code屁股aspx页面(你可以删除那些并在标记输入正确的继承类)。使您获得MVC和Visual Studio的善良实际上是转化项目类型(添加新的视图,后藤控制器等)会采取一些与玩耍。我最好的建议是建立在VS 2008中一个新的MVC项目和一个新的Web应用程序项目,并以纯文本的.csproj文件进行比较。还有,告诉VS项目模板的长字符串值。

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.

相信我这样做的工作。我以前做过这对我自己的遗产项目。我不记得我是怎么发现的项目类型的钥匙,除了试验/错误/消除。 ASP.Net MVC确实在同一项目中的web表单发挥不错。

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.

更新:我觉得你可以换到一个MVC项目类型,它仍然是在的.csproj文件的PropertyGroup使用这些Web应用程序。比较那些你所拥有的和改变的人是不同的充,一定要复制/备份文件。

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>

更新2::您会不会影响你的项目还是非常影响它。如果你是联合国轻松它进行备份和玩。如果你遇到的改变,你总是有备份。起初我持怀疑态度,但很高兴我去了MVC的路径。

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.

这篇关于你将如何撒,在ASP.Net MVC到现有的网站项目?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆