WebMatrix Razor页面和全局使用语句

时间:2021-03-22 01:44:05

How can I setup global usings for all my .cshtml pages in WebMatrix Razor context (not ASP.NET MVC Razor)?

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

So instead of putting @using System.Web.Optimization on top of each .cshtml file where I need to include @Scripts.Render() I would put it into one single place instead.

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

3 个解决方案

#1


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>

See also: Building single-page app with AngularJS and ASP.NET MVC 4

另请参阅:使用AngularJS和ASP.NET MVC 4构建单页面应用程序

#2


1  

Edited Please take a look into the following posting. They discussing exactly your question, I am sure you can get the idea from there as to what to do:

编辑请看下面的帖子。他们正在讨论你的问题,我相信你可以从那里得到关于做什么的想法:

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

当前上下文中不存在名称“Assets”

Hope this will help you

希望对你有帮助

#3


0  

For webmatrix use the following in the web.config configuartion

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

  <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>

#1


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>

See also: Building single-page app with AngularJS and ASP.NET MVC 4

另请参阅:使用AngularJS和ASP.NET MVC 4构建单页面应用程序

#2


1  

Edited Please take a look into the following posting. They discussing exactly your question, I am sure you can get the idea from there as to what to do:

编辑请看下面的帖子。他们正在讨论你的问题,我相信你可以从那里得到关于做什么的想法:

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

当前上下文中不存在名称“Assets”

Hope this will help you

希望对你有帮助

#3


0  

For webmatrix use the following in the web.config configuartion

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

  <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>

相关文章