简体   繁体   English

捆绑CSS文件-找不到文件

[英]Bundling css file - file not found

i am using BundleConfig to bundle my css and javascript files in mvc 4.0 project. 我正在使用BundleConfig将我的CSS和javascript文件捆绑在mvc 4.0项目中。 just started using it, but somehow my bundled css file get 404 status from the server. 刚开始使用它,但是以某种方式我捆绑的css文件从服务器获取404状态。 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. 我已经在根目录中创建了该文件夹:“ CSSJSBundles”。 Do i need to? 我需要吗? or it is just virtual folder mvc uses? 还是只是mvc使用的虚拟文件夹? Also do i need to put any settings in Global.aspx? 我还需要在Global.aspx中放入任何设置吗?

I also deleted the folder, still there is 404 error for that bundled css file. 我还删除了该文件夹,该捆绑的CSS文件仍然存在404错误。

  1. As noted in one of the previous answers, you need to change ScriptBundle to StyleBundle . 如前面的答案之一所述,您需要将ScriptBundle更改为StyleBundle

  2. 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. 当您要查看输出时使用该行,因为它将在发布模式下发生。

  3. No you do not need that folder CSSJSBundles to physically exist. 不,您不需要该文件夹CSSJSBundles实际存在。

  4. It appears you need to add this line to your Application_Start() in your global.asax.cs file: BundleConfig.RegisterBundles(BundleTable.Bundles); 似乎您需要将此行添加到global.asax.cs文件中的Application_Start()中: BundleConfig.RegisterBundles(BundleTable.Bundles);

u have to use StyleBundle ... not a ScriptBundle since it is a css file. 您必须使用StyleBundle ...而不是ScriptBundle,因为它是css文件。

for js files, u should use ScriptBundle. 对于js文件,您应该使用ScriptBundle。

try 尝试

public static void RegisterBundles(BundleCollection bundles)
        {
            bundles.Add(new StyleBundle("~/bundles/3rdpartycss").Include(
                        "~/Content/jquery.jnotify.css"
                        ));
        }

:) :)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM