【发布时间】:2012-08-27 12:15:27
【问题描述】:
考虑到这个文件夹结构:
Content
style1.css
style2.css
CssFolder1
style3.css
style4.css
style5.css
style6.css
在应用程序中,我想包含style1.css、style2.css、style3.css 和style4.css。
我正在这样做:
public class BundleConfig
{
public static void RegisterBundles(BundleCollection bundles)
{
bundles.Add(new StyleBundle("~/styles/main").Include("~/Content/style1.css", "~/Content/style2.css"));
bundles.Add(new StyleBundle("~/styles/custom").Include("~/Content/CssFolder1/style3.css","~/Content/CssFolder1/style4.css"));
}
}
在_Layout.cshtml 中,我将其渲染为:
@Styles.Render("~/styles/main", "~/styles/custom")
仅加载 style1.css 和 style2.css。如何正确加载style3.css和style4.css?
LE:内容是解决方案中的一个文件夹,该文件夹中的所有文件都将添加到解决方案中。
【问题讨论】:
-
您的代码看起来不错。您使用的是哪个网络服务器 VS 开发服务器、IIS express、IIS?你确定文件在那里吗?如果您使用
<link href="@Url.Content("~/Content/CssFolder1/style3.css")" rel="stylesheet" type="text/css" />手动包含它们会发生什么? -
我已经尝试过了,如果我手动包含它们,它们就会被加载。我正在使用 VS 开发服务器。
-
您是否使用表单身份验证?如果是这样,您是否允许公开访问样式/自定义?
标签: asp.net-mvc .net-4.5 asp.net-optimization bundling-and-minification