简体   繁体   中英

Bundling css file - file not found

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.

  1. As noted in one of the previous answers, you need to change ScriptBundle to 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.

  4. It appears you need to add this line to your Application_Start() in your global.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"
                        ));
        }

:)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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