WebMatrix Razor页面和全局使用语句

时间:2012-09-23 12:11:12

标签: asp.net asp.net-mvc razor using webmatrix

如何在WebMatrix Razor上下文(不是ASP.NET MVC Razor)中为我的所有.cshtml页面设置全局使用?

因此,不要将@using System.Web.Optimization置于我需要包含@Scripts.Render()的每个.cshtml文件的顶部,而是将其放在一个单独的位置。

3 个答案:

答案 0 :(得分:3)

<?xml version="1.0" encoding="utf-8"?>
<configuration>
  <configSections>
    <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>
  <appSettings>
    <add key="webpages:Version" value="2.0.0.0" />
    <add key="webpages:Enabled" value="true" />
  </appSettings>
  <system.web.webPages.razor>
    <pages pageBaseType="System.Web.WebPages.WebPage">
      <namespaces>
        <add namespace="System.Web.Helpers" />
        <add namespace="System.Web.Mvc" />
        <add namespace="System.Web.Mvc.Ajax" />
        <add namespace="System.Web.Mvc.Html" />
        <add namespace="System.Web.Optimization" />
        <add namespace="System.Web.Routing" />
        <add namespace="System.Web.WebPages" />
      </namespaces>
    </pages>
  </system.web.webPages.razor>
</configuration>

另请参阅:Building single-page app with AngularJS and ASP.NET MVC 4

答案 1 :(得分:1)

<强>被修改 请查看以下帖子。他们正在讨论你的问题,我相信你可以从那里得到关于该做什么的想法:

The name 'Assets' does not exist in the current context

希望这会对你有所帮助

答案 2 :(得分:0)

对于webmatrix,请在web.config配置中使用以下内容

  <runtime>
    <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
      <dependentAssembly>
        <assemblyIdentity name="System.Web.Helpers" publicKeyToken="31bf3856ad364e35"/>
        <bindingRedirect oldVersion="1.0.0.0-3.0.0.0" newVersion="3.0.0.0"/>
      </dependentAssembly>
      <dependentAssembly>
        <assemblyIdentity name="System.Web.WebPages" publicKeyToken="31bf3856ad364e35"/>
        <bindingRedirect oldVersion="1.0.0.0-3.0.0.0" newVersion="3.0.0.0"/>
      </dependentAssembly>
    </assemblyBinding>
  </runtime>