【问题标题】:image URL concern for CSS changer inside MVC controllerMVC 控制器中 CSS 转换器的图像 URL 问题
【发布时间】:2015-06-25 07:21:27
【问题描述】:

我目前有一个样式控制器,它调用 StyleResolver 操作,它让我可以在将要使用的 css 主题之间切换。

if (contractState == "FL" || contractState == "TX")
{
    Response.ContentType = "text/css";
    return Razor.Parse(System.IO.File.ReadAllText(Server.MapPath("~/Content/genesis-theme-flat/jquery-ui-1.10.4.custom.css")));
}
else if (contractState == "AZ" || contractState == "CA" ||
    contractState == "GA" || contractState == "MO" ||
    contractState == "NM" || contractState == "SC" ||
    contractState == "UT")
{
    Response.ContentType = "text/css";
    return Razor.Parse(System.IO.File.ReadAllText(Server.MapPath("~/Content/nowcom-theme-flat/jquery-ui-1.10.2.custom.css")));
}

现在的问题是这两个文件中所有与图像相关的css,导致文件路径问题

.ui-widget-content {
    border: 1px solid #ececec;
    background: #ffffff url("images/ui-bg_flat_0_ffffff_40x100.png") 50% 50% repeat-x;
    color: #333;
}
.ui-widget-header {
    border: 1px solid #ececec;
    background: #ececec url("images/ui-bg_highlight-soft_0_ececec_1x100.png") 50% 50% repeat-x;
    color: #960000;
    font-weight: bold;
}     

这些图像在这些文件夹中。

结果路径:

http://localhost:50402/Style/images/ui-bg_flat_0_ffffff_40x100.png 404 (Not Found)
http://localhost:50402/Style/images/ui-bg_highlight-soft_0_ececec_1x100.png 404 (Not Found)

似乎调用 Razor.Parse 后,URL 没有正确指向 "Content/name-of-theme/images" 文件夹,而是包含调用样式控制器。如何修复显示的路径以解决图像的 404 问题?

【问题讨论】:

    标签: html css asp.net-mvc razor


    【解决方案1】:

    通过这种方式强制 url 路径修复。

    url(/content/genesis-theme-flat/images/ui-bg_glass_0_960000_1x400.png)

    【讨论】:

      猜你喜欢
      • 2013-07-29
      • 2017-12-11
      • 2014-02-23
      • 1970-01-01
      • 2012-04-16
      • 2011-03-19
      • 2011-06-09
      • 1970-01-01
      • 2010-10-11
      相关资源
      最近更新 更多