admin管理员组文章数量:1290394
i am using BundleConfig to bundle my css and javascript files in mvc 4.0 project. just started using it, but somehow my bundled css file get 404 status from the server. wonder what is the problem.
Here is my setting;
public class BundleConfig
{
public static void RegisterBundles(BundleCollection bundles)
{
bundles.Add(new ScriptBundle("~/CSSJSBundles/3rdpartycss").Include(
"~/Scripts/jquery.jnotify.css"
)); }
BundleTable.EnableOptimizations = true;
}
I have created that folder: 'CSSJSBundles' in my root. Do i need to? or it is just virtual folder mvc uses? Also do i need to put any settings in Global.aspx?
I also deleted the folder, still there is 404 error for that bundled css file.
i am using BundleConfig to bundle my css and javascript files in mvc 4.0 project. just started using it, but somehow my bundled css file get 404 status from the server. wonder what is the problem.
Here is my setting;
public class BundleConfig
{
public static void RegisterBundles(BundleCollection bundles)
{
bundles.Add(new ScriptBundle("~/CSSJSBundles/3rdpartycss").Include(
"~/Scripts/jquery.jnotify.css"
)); }
BundleTable.EnableOptimizations = true;
}
I have created that folder: 'CSSJSBundles' in my root. Do i need to? or it is just virtual folder mvc uses? Also do i need to put any settings in Global.aspx?
I also deleted the folder, still there is 404 error for that bundled css file.
Share Improve this question edited Jan 28, 2013 at 5:06 abatishchev 100k88 gold badges301 silver badges442 bronze badges asked Jan 28, 2013 at 4:08 HotFrostHotFrost 1,6054 gold badges18 silver badges25 bronze badges 10- Please show how you are referencing your bundle and also how the reference renders to the client. – MikeSmithDev Commented Jan 28, 2013 at 4:32
- Also consider moving your css to a folder called "content". "Scripts" is typically for javascript files. – MikeSmithDev Commented Jan 28, 2013 at 4:48
- Thanks for the answers all. First, great find on that 'StyleBundle'. I replaced it. Second, it still does not work. Do I have to have such a folder in my project 'CSSJSBundle'? Third, here is how I reference it in my _layout file: @Styles.Render("~/CSSJSBundles/3rdpartycss", "~/CSSJSBundles/widgetscss", "~/CSSJSBundles/controllerscss"); I tried to switch the debug mode to 'off' still does not work.. But isn't that line:'BundleTable.EnableOptimizations = true;' should take care about enabling bundling? Thanks for the help! – HotFrost Commented Jan 28, 2013 at 15:26
-
What happens when you just use
@Styles.Render("~/CSSJSBundles/3rdpartycss")
– MikeSmithDev Commented Jan 28, 2013 at 15:42 -
1
@user194033 your global.asax.cs should have
BundleConfig.RegisterBundles(BundleTable.Bundles);
if you are using MVC4. – MikeSmithDev Commented Jan 28, 2013 at 17:47
2 Answers
Reset to default 6As noted in one of the previous answers, you need to change
ScriptBundle
toStyleBundle
.BundleTable.EnableOptimizations = true;
isn't required. What that does is force bundling and minification to occur when you are in debug mode. The default action is not NOT bundle/minify in debug mode so you can debug more easily. Use that line when you want to see the output as it will happen in release mode.No you do not need that folder
CSSJSBundles
to physically exist.It appears you need to add this line to your
Application_Start()
in yourglobal.asax.cs
file:BundleConfig.RegisterBundles(BundleTable.Bundles);
u have to use StyleBundle ... not a ScriptBundle since it is a css file.
for js files, u should use ScriptBundle.
try
public static void RegisterBundles(BundleCollection bundles)
{
bundles.Add(new StyleBundle("~/bundles/3rdpartycss").Include(
"~/Content/jquery.jnotify.css"
));
}
:)
本文标签: cBundling css filefile not foundStack Overflow
版权声明:本文标题:c# - Bundling css file - file not found - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1741496063a2381842.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论