[英]How do I use ASP.NET MVC RC with Visual Studio Web Developer 2008 SP1?
When I go to File > New Website there isn't a template for MVC. 当我转到文件>新网站时,没有用于MVC的模板。 I googled "how to use MVC with vwd?"
我在Google上搜索了“如何在vwd中使用MVC?” and these links came up
这些链接出现了
http://geekswithblogs.net/jwhitehorn/archive/2007/12/10/117569.aspx http://geekswithblogs.net/jwhitehorn/archive/2007/12/10/117569.aspx
http://jerusahat.wordpress.com/2007/12/12/aspnet-mvc-template-for-visual-web-developer-2008-express/ http://jerusahat.wordpress.com/2007/12/12/aspnet-mvc-template-for-visual-web-developer-2008-express/
http://www.lazycoder.com/weblog/2007/12/10/using-the-aspnet-mvc-framework-with-visual-web-developer-express/ http://www.lazycoder.com/weblog/2007/12/10/using-the-aspnet-mvc-framework-with-visual-web-developer-express/
but none of them seem to work. 但它们似乎都不起作用。 I just get assembly reference errors and after I hookup the assemblies I get:
我刚得到程序集引用错误,并且在连接程序集后得到:
Error 1 'System.Web.Routing.Route' does not contain a constructor that takes '0' arguments 错误1'System.Web.Routing.Route'不包含采用'0'参数的构造函数
Error 2 Cannot implicitly convert type 'AnonymousType#1' 错误2无法隐式转换类型'AnonymousType#1'
Error 3 Cannot implicitly convert type 'System.Type' to 'System.Web.Routing.IRouteHandler'. 错误3无法将类型'System.Type'隐式转换为'System.Web.Routing.IRouteHandler'。
and so on... 等等...
Is VWD2008 compatible with ASP.NET MVC? VWD2008与ASP.NET MVC兼容吗?
you also need to have sp1 installed. 您还需要安装sp1。
if you do have vwd express 2008 sp1 installed, you might have the same problem i had when i first went looking for MVC in the vwd menu. 如果您确实安装了vwd express 2008 sp1,则可能遇到与我第一次在vwd菜单中查找MVC时遇到的相同问题。
try going to 'Tools' -> 'Import and Export Settings' and then 'Reset all settings.' 尝试转到“工具”->“导入和导出设置”,然后“重置所有设置”。
after that, you need to create a new project and select the MVC template. 之后,您需要创建一个新项目并选择MVC模板。 (don't create a new web site).
(不要创建新的网站)。
Make sure you install Web Developer 2008 Express SP1 before you install ASP.NET MVC as well. 在安装ASP.NET MVC之前,请确保安装了Web Developer 2008 Express SP1。
I used the Web Platforum Installer to install both at the same time, and ASP.NET MVC didn't show up when I go to create new project. 我使用Web Platforum Installer同时安装了两者,而去创建新项目时ASP.NET MVC没有出现。 I uninstalled ASP.NET MVC then installed it again, then it showed up in New Project menu.
我卸载了ASP.NET MVC,然后再次安装了它,然后它显示在“新建项目”菜单中。
Yes, I'm sure it is compatible with ASP.NET MVC.
是的,我敢肯定,这是与ASP.NET MVC兼容。
All you need is to add the assemblies to bin
folder and edit Web.config
and Global.asax
files. 您所需要做的就是将程序集添加到
bin
文件夹中,并编辑Web.config
和Global.asax
文件。
Start with an empty plain ASP.NET site (not the ones in templates as I've not tested them). 从一个空的纯ASP.NET站点开始(而不是模板中的站点,因为我尚未对其进行测试)。 Add the assemblies to
bin
and... 将程序集添加到
bin
并...
Web.config
should look like: Web.config
应该看起来像:
<?xml version="1.0"?>
<configuration>
<configSections>
<sectionGroup name="system.web.extensions" type="System.Web.Configuration.SystemWebExtensionsSectionGroup, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35">
<sectionGroup name="scripting" type="System.Web.Configuration.ScriptingSectionGroup, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35">
<section name="scriptResourceHandler" type="System.Web.Configuration.ScriptingScriptResourceHandlerSection, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" requirePermission="false" allowDefinition="MachineToApplication"/>
<sectionGroup name="webServices" type="System.Web.Configuration.ScriptingWebServicesSectionGroup, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35">
<section name="jsonSerialization" type="System.Web.Configuration.ScriptingJsonSerializationSection, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" requirePermission="false" allowDefinition="Everywhere" />
<section name="profileService" type="System.Web.Configuration.ScriptingProfileServiceSection, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" requirePermission="false" allowDefinition="MachineToApplication" />
<section name="authenticationService" type="System.Web.Configuration.ScriptingAuthenticationServiceSection, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" requirePermission="false" allowDefinition="MachineToApplication" />
<section name="roleService" type="System.Web.Configuration.ScriptingRoleServiceSection, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" requirePermission="false" allowDefinition="MachineToApplication" />
</sectionGroup>
</sectionGroup>
</sectionGroup>
</configSections>
<appSettings/>
<system.web>
<compilation debug="false">
<assemblies>
<add assembly="System.Core, Version=3.5.0.0, Culture=neutral, PublicKeyToken=B77A5C561934E089"/>
<add assembly="System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"/>
<add assembly="System.Web.Abstractions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"/>
<add assembly="System.Web.Routing, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"/>
<add assembly="System.Web.Mvc, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"/>
<add assembly="System.Data.DataSetExtensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=B77A5C561934E089"/>
<add assembly="System.Xml.Linq, Version=3.5.0.0, Culture=neutral, PublicKeyToken=B77A5C561934E089"/>
<add assembly="System.Data.Linq, Version=3.5.0.0, Culture=neutral, PublicKeyToken=B77A5C561934E089" />
</assemblies>
</compilation>
<pages>
<controls>
<add tagPrefix="asp" namespace="System.Web.UI" assembly="System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"/>
<add tagPrefix="asp" namespace="System.Web.UI.WebControls" assembly="System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"/>
</controls>
<namespaces>
<add namespace="System.Web.Mvc"/>
<add namespace="System.Web.Mvc.Ajax"/>
<add namespace="System.Web.Mvc.Html"/>
<add namespace="System.Web.Routing"/>
<add namespace="System.Linq"/>
<add namespace="System.Collections.Generic"/>
</namespaces>
</pages>
<httpHandlers>
<remove verb="*" path="*.asmx"/>
<add verb="*" path="*.asmx" validate="false" type="System.Web.Script.Services.ScriptHandlerFactory, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"/>
<add verb="*" path="*_AppService.axd" validate="false" type="System.Web.Script.Services.ScriptHandlerFactory, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"/>
<add verb="GET,HEAD" path="ScriptResource.axd" type="System.Web.Handlers.ScriptResourceHandler, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" validate="false"/>
<add verb="*" path="*.mvc" validate="false" type="System.Web.Mvc.MvcHttpHandler, System.Web.Mvc, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"/>
</httpHandlers>
<httpModules>
<add name="ScriptModule" type="System.Web.Handlers.ScriptModule, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"/>
<add name="UrlRoutingModule" type="System.Web.Routing.UrlRoutingModule, System.Web.Routing, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" />
</httpModules>
</system.web>
<system.codedom>
<compilers>
<compiler language="c#;cs;csharp" extension=".cs" warningLevel="4"
type="Microsoft.CSharp.CSharpCodeProvider, System, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
<providerOption name="CompilerVersion" value="v3.5"/>
<providerOption name="WarnAsError" value="false"/>
</compiler>
<compiler language="vb;vbs;visualbasic;vbscript" extension=".vb" warningLevel="4"
type="Microsoft.VisualBasic.VBCodeProvider, System, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
<providerOption name="CompilerVersion" value="v3.5"/>
<providerOption name="OptionInfer" value="true"/>
<providerOption name="WarnAsError" value="false"/>
</compiler>
</compilers>
</system.codedom>
<system.web.extensions/>
<system.webServer>
<validation validateIntegratedModeConfiguration="false"/>
<modules runAllManagedModulesForAllRequests="true">
<remove name="ScriptModule" />
<remove name="UrlRoutingModule" />
<add name="ScriptModule" preCondition="managedHandler" type="System.Web.Handlers.ScriptModule, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"/>
<add name="UrlRoutingModule" type="System.Web.Routing.UrlRoutingModule, System.Web.Routing, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" />
</modules>
<handlers>
<remove name="WebServiceHandlerFactory-Integrated"/>
<remove name="ScriptHandlerFactory" />
<remove name="ScriptHandlerFactoryAppServices" />
<remove name="ScriptResource" />
<remove name="MvcHttpHandler" />
<remove name="UrlRoutingHandler" />
<add name="ScriptHandlerFactory" verb="*" path="*.asmx" preCondition="integratedMode"
type="System.Web.Script.Services.ScriptHandlerFactory, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"/>
<add name="ScriptHandlerFactoryAppServices" verb="*" path="*_AppService.axd" preCondition="integratedMode"
type="System.Web.Script.Services.ScriptHandlerFactory, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"/>
<add name="ScriptResource" preCondition="integratedMode" verb="GET,HEAD" path="ScriptResource.axd" type="System.Web.Handlers.ScriptResourceHandler, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" />
<add name="MvcHttpHandler" preCondition="integratedMode" verb="*" path="*.mvc" type="System.Web.Mvc.MvcHttpHandler, System.Web.Mvc, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"/>
<add name="UrlRoutingHandler" preCondition="integratedMode" verb="*" path="UrlRouting.axd" type="System.Web.HttpForbiddenHandler, System.Web, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" />
</handlers>
</system.webServer>
</configuration>
Global.asax should contain something like: Global.asax应该包含以下内容:
public static void RegisterRoutes(RouteCollection routes)
{
routes.IgnoreRoute("{resource}.axd/{*pathInfo}");
routes.MapRoute(
"Default", // Route name
"{controller}/{action}/{id}", // URL with parameters
new { controller = "Home", action = "Index", id = "" } // Parameter defaults
);
}
protected void Application_Start()
{
RegisterRoutes(RouteTable.Routes);
}
Default.aspx
should have this Page_Load
in code behind if you are using IIS7 Classic or IIS6 or below: 如果您使用的是IIS7 Classic或IIS6或更低版本,则
Default.aspx
在代码后应具有此Page_Load
:
public void Page_Load(object sender, System.EventArgs e)
{
HttpContext.Current.RewritePath(Request.ApplicationPath, false);
IHttpHandler httpHandler = new MvcHttpHandler();
httpHandler.ProcessRequest(HttpContext.Current);
}
You should have a Views
folder with a Web.config
looking like: 您应该具有一个带有
Web.config
的Views
文件夹,如下所示:
<?xml version="1.0"?>
<configuration>
<system.web>
<httpHandlers>
<add path="*" verb="*"
type="System.Web.HttpNotFoundHandler"/>
</httpHandlers>
<pages
validateRequest="false"
pageParserFilterType="System.Web.Mvc.ViewTypeParserFilter, System.Web.Mvc, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"
pageBaseType="System.Web.Mvc.ViewPage, System.Web.Mvc, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"
userControlBaseType="System.Web.Mvc.ViewUserControl, System.Web.Mvc, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35">
<controls>
<add assembly="System.Web.Mvc, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" namespace="System.Web.Mvc" tagPrefix="mvc" />
</controls>
</pages>
</system.web>
<system.webServer>
<validation validateIntegratedModeConfiguration="false"/>
<handlers>
<remove name="BlockViewHandler"/>
<add name="BlockViewHandler" path="*" verb="*" preCondition="integratedMode" type="System.Web.HttpNotFoundHandler"/>
</handlers>
</system.webServer>
</configuration>
Put the views in a subfolder in Views
. 将视图放在
Views
的子文件夹中。 They should inherit from System.Web.Mvc.ViewPage
. 它们应该继承自
System.Web.Mvc.ViewPage
。 Put the controllers in Controllers
namespace with a class name ending with Controller
. 将控制器放在
Controllers
命名空间中,其类名以Controller
结尾。
This should do the job. 这应该做的工作。
But you did install asp.net mvc rc1 ( link ), right? 但是您确实安装了asp.net mvc rc1( link ),对吗? In vs 2008 (at least professional) to get the template for asp.net mvc you have to first install asp.net mvc.
在vs 2008(至少是专业人士)中,要获取asp.net mvc的模板,您必须首先安装asp.net mvc。 If you did install it, then never mind (i'm asking because you wrote that you can't see the template).
如果您确实安装了它,那就没关系了(我问是因为您写道您看不到模板)。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.