【问题标题】:I have no style in my asp.net mvc application after upgrading to mvc rc升级到 mvc rc 后,我的 asp.net mvc 应用程序没有样式
【发布时间】:2009-02-14 02:02:56
【问题描述】:

我很困惑,因为我使用的是集成的 iis7,所以我的项目中不需要 default.aspx。但是,在运行时升级到 rc 后,我的站点中的任何地方都没有样式。这是我指向位于母版页旁边的样式表的链接。在设计时,vs 能够获取样式表,所以我不知道可能出了什么问题。

<link href="Stylesheet.css" rel="stylesheet" type="text/css" />

在运行时计算为

<link href="Views/Shared/Stylesheet.css" rel="stylesheet" type="text/css" />

看起来应该没问题。

【问题讨论】:

    标签: asp.net-mvc stylesheet


    【解决方案1】:

    我会将您的样式移至 Content/Styles 目录;这是他们通常居住的地方。我怀疑路由引擎会阻止直接访问 View 目录中的任何文件作为预防措施(因此人们看不到您的视图代码)。您需要将链接更改为:

     <link href="<%= Url.Content( "~/Content/Styles/Stylesheet.css" )"
           rel="stylesheet"
           type="text/css" />
    

    或者如果你想硬编码根路径:

    <link href="/Content/Styles/Stylesheet.css"
          rel="stylesheet"
          type="text/css" />
    

    我做了一些与前者类似的事情,但使用了一种扩展方法,将当前日期作为查询参数 (?d=YYYYMMDD) 格式附加到 url 的末尾,以便缓存的 CSS 文件在我进行更改时定期更新。但是,如果这样做,则需要将后者包含在 if (false) 指令中,以确保不会丢失智能感知。

    <% if (false) { %>
      <link href="/Content/Styles/Stylesheet.css"
            rel="stylesheet"
            type="text/css" />
    <% } %>
    

    【讨论】:

      猜你喜欢
      • 2013-06-12
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-11-15
      • 1970-01-01
      相关资源
      最近更新 更多