用Razor v2替换MVC3 View Engine?

时间:2012-04-23 16:47:50

标签: asp.net-mvc-3 razor

有没有办法设置我们的MVC3应用程序以使用更新版本的Razor?我尝试使用NuGet,但显然必须有一些额外的布线需要完成,因为我没有看到URL功能和条件属性等新功能。

2 个答案:

答案 0 :(得分:2)

  1. 安装ASP.NET MVC 4
  2. 删除对System.Web.WebPages 1.0和System.Web.Helpers 1.0的引用,然后添加对System.Web.WebPages 2.0和System.Web.Helpers 2.0的引用
  3. 在根web.config文件中,添加/更新这些设置:

    <appSettings>
        <add key="webpages:Version" value="2.0.0.0" />
        <add key="webpages:Enabled" value="true" />
        <add key="PreserveLoginUrl" value="true" />
    ...
    <add assembly="System.Web.WebPages, Version=2.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" />
    <add assembly="System.Web.Helpers, Version=2.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" />
    ...
    <dependentAssembly>
        <assemblyIdentity name="System.Web.WebPages" publicKeyToken="31bf3856ad364e35" />
        <bindingRedirect oldVersion="1.0.0.0-2.0.0.0" newVersion="2.0.0.0" />
    </dependentAssembly>
    <dependentAssembly>
        <assemblyIdentity name="System.Web.Helpers" publicKeyToken="31bf3856ad364e35" />
        <bindingRedirect oldVersion="1.0.0.0-2.0.0.0" newVersion="2.0.0.0" />
    </dependentAssembly>
    
  4. Inside Views web.config文件,添加/更新这些设置:

    <sectionGroup name="system.web.webPages.razor" type="System.Web.WebPages.Razor.Configuration.RazorWebSectionGroup, System.Web.WebPages.Razor, Version=2.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35">
        <section name="host" type="System.Web.WebPages.Razor.Configuration.HostSection, System.Web.WebPages.Razor, Version=2.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" requirePermission="false" />
        <section name="pages" type="System.Web.WebPages.Razor.Configuration.RazorPagesSection, System.Web.WebPages.Razor, Version=2.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" requirePermission="false" />
    </sectionGroup>
    </configSections>
    <system.web.webPages.razor>
        <host factoryType="System.Web.Mvc.MvcWebRazorHostFactory, System.Web.Mvc, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" />
    

答案 1 :(得分:0)

在Asp.net论坛上询问并发现NuGet上的RazorEngine与内置的Razor View Engine不完全相同。