渲染样式捆绑包与样式链接不同

时间:2014-10-04 22:25:43

标签: css asp.net-mvc layout

我有一个使用来自keenthemes的Metronic模板的ASP.NET MVC应用程序。

当我在我的布局中为我的CSS使用捆绑时,它不能很好地工作。大多数 图标 不会出现

如果我切换到直接链接,那么一切正常。

Javascript没问题。

捆绑包配置和布局使用:

bundles.Add(new StyleBundle("~/bundles/metronic-app").Include(
    "~/assets/global/plugins/font-awesome/css/font-awesome.min.css",
    "~/assets/global/plugins/simple-line-icons/simple-line-icons.min.css",
    "~/assets/global/plugins/uniform/css/uniform.default.css",
    "~/assets/global/plugins/bootstrap-switch/css/bootstrap-switch.min.css",
    "~/assets/global/css/components.css",
    "~/assets/global/css/plugins.css",
    "~/assets/admin/layout2/css/layout.css",
    "~/assets/admin/layout2/css/themes/default.css",
    "~/assets/admin/layout2/css/custom.css"));


@Styles.Render("~/bundles/metronic-app")

直接链接:

<link href="~/assets/global/plugins/font-awesome/css/font-awesome.min.css" rel="stylesheet" type="text/css">
<link href="~/assets/global/plugins/simple-line-icons/simple-line-icons.min.css" rel="stylesheet" type="text/css">
<link href="~/assets/global/plugins/uniform/css/uniform.default.css" rel="stylesheet" type="text/css">
<link href="~/assets/global/plugins/bootstrap-switch/css/bootstrap-switch.min.css" rel="stylesheet" type="text/css" />
<!-- END GLOBAL MANDATORY STYLES -->
<!-- BEGIN THEME STYLES -->
<link href="~/assets/global/css/components.css" rel="stylesheet" type="text/css" />
<link href="~/assets/global/css/plugins.css" rel="stylesheet" type="text/css" />
<link href="~/assets/admin/layout2/css/layout.css" rel="stylesheet" type="text/css" />
<link id="style_color" href="~/assets/admin/layout2/css/themes/default.css" rel="stylesheet" type="text/css" />
<link href="~/assets/admin/layout2/css/custom.css" rel="stylesheet" type="text/css" />

以下是Chrome控制台的错误:

console errors

1 个答案:

答案 0 :(得分:0)

我应该在我的捆绑配置中使用CssrewriteUrlTransform类,以使资产的路径成为绝对路径。

这是有效的:

bundles.Add(new StyleBundle("~/bundles/metronic-app").Include(
                "~/assets/global/plugins/uniform/css/uniform.default.css",
                "~/assets/global/plugins/bootstrap-switch/css/bootstrap-switch.min.css",
                "~/assets/global/css/components.css",
                "~/assets/global/css/plugins.css",
                "~/assets/admin/layout2/css/custom.css")
                .Include("~/assets/admin/layout2/css/layout.css", new CssRewriteUrlTransform())
                .Include("~/assets/admin/layout2/css/themes/default.css", new CssRewriteUrlTransform())
                .Include("~/assets/global/plugins/font-awesome/css/font-awesome.min.css", new CssRewriteUrlTransform())
                .Include("~/assets/global/plugins/simple-line-icons/simple-line-icons.min.css",new CssRewriteUrlTransform()));

提示SO Question