WebForms和MVC能够生活在一个单一的项目? [英] Can WebForms and MVC live in a single project?
问题描述
我宁愿做MVC作为常规的WebForms发展吃了我的灵魂。
I'd rather be doing MVC as the regular WebForms development eats my soul.
不过,我已经被赋予了相当可观的WebForms项目,一堆功能添加到。
However, I've been given a fairly sizable WebForms project to add a bunch of features to.
反正对WebForms和ASP.NET MVC中的单个项目共存,甚至共同处理的网站?我知道我要求一个黑客。
Is there anyway for WebForms and ASP.NET MVC to coexist in single project or even jointly handle the website? I know I am asking for a hack.
推荐答案
下面去......
- 确保您的项目是针对.NET 3.5
- 添加引用(并确保它们复制到本地)的大3组件的MVC(System.Web.Mvc,.Abstractions,.Routing)
- 添加Global.asax中,如果你不已经有一个在你的项目。
- 转到后面的Global.asax code和添加必要的code,使它看起来就像是一个MVC的Global.asax(我不会打字出来,只需创建一个新的MVC项目,看在Global.asax并添加您当前的Global.asax code背后缺乏的事情)
- 创建的控制器和放顶层文件夹; 意见
- 为您相应的控制器上创建意见的子文件夹(如查看 - >主页)
- 当您将文件添加到的.aspx您查看文件夹,请务必将基类的System.Web.UI改为System.Web.ViewPage并删除标记 li>
- 启动一个新的空MVC项目和做在web.configUrlRoutingModule一个查找和那些refrences在同一个地方添加到您的WebForms的web.config
- 检查System.Web程序 - >页面 - >命名空间的新的MVC项目节点和MVC特定的人添加到您的WebForms的web.config
这是一个非常粗略的解释,但你要的悬崖笔记。这个故事的寓意是用新的/空白MVC项目跟踪和沿线web.config中添加必要的条目,引用了必要的组件,并为MVC模式创建正确的文件结构。
This is a very rough explanation but you asked for the cliff notes. Moral of the story is to follow along with a new/blank mvc project and add the necessary entries in web.config, reference the necessary assemblies, and create the correct file structure for the mvc pattern.
这篇关于WebForms和MVC能够生活在一个单一的项目?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!