Bundled css link gets a 404 error

前端 未结 6 979
不知归路
不知归路 2020-12-09 16:24

I am trying to get bundling to work in ASP.NET MVC 4. I am getting a 404 error from the link generated for the bundled CSS. I have done the following:

  1. Ins

6条回答
  •  失恋的感觉
    2020-12-09 16:58

    It seems that you have missed the step in which you apply your configuration by calling RegisterBundles in Application_Start:

    protected void Application_Start()
    {
        ...
        BundleConfig.RegisterBundles(BundleTable.Bundles);
        ...
    }
    

    Usually in cases where the BundleConfig class is already there (either as a part of the project template or created by NuGet package during the installation) this call is also already present - this is why many tutorials are implicit about it.

    You should also be aware that the BundleConfig class is there for separation of concerns and in order to keep the Application_Start clean. In simple cases nothing prevents you from registering bundles directly in Application_Start:

    protected void Application_Start()
    {
        ...
        BundleTable.Bundles.Add(new StyleBundle("~/bundles/styles/cvi").Include("~/mainstyles.css"));
    
        ...
    }
    

提交回复
热议问题