【问题标题】:how to add css file to mvc4如何将css文件添加到mvc4
【发布时间】:2013-06-06 13:03:28
【问题描述】:

我有一个想要放入布局的 css 文件。 在我写的 web.config 文件中:

<location path="App_themes/default.css">
          <system.web>
             <authorization>
                <allow users="*"/>
             </authorization>
          </system.web>
       </location>

我在 layout.cshtml 中写道:

 <style>
        h2 {
            color:red;
        }

          @Styles.Render("~/App_themes/css")  

    </style>

但它无法识别该行:@styles.render 我该怎么办?

【问题讨论】:

    标签: css layout asp.net-mvc-4


    【解决方案1】:

    @Styles.Render("~/App_Themes/css") 放在布局页面的头部元素中 (_Layout.cshtml)

    将样式h2 { color: red; } 放入位于theApp_Themes/css 子文件夹中的样式表中。

    【讨论】:

      【解决方案2】:

      请在 iis 中运行项目 项目/右键/properties/web/使用本地IIS web服务器

      【讨论】:

        【解决方案3】:

        Styles.Render in MVC4

        您需要阅读捆绑和缩小以清楚地了解正在发生的事情,但有一点是肯定的,@Styles.Render("~/App_Themes/css") 调用应该在&lt;style/&gt; 标记的上下文之外进行。

        @Styles.Render("~/App_Themes/css")
        <style> h2 { color: red; } </style>
        

        【讨论】:

          猜你喜欢
          • 1970-01-01
          • 2014-02-16
          • 2018-05-11
          • 2021-10-31
          • 2015-11-23
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          相关资源
          最近更新 更多