Search code examples
c#monomonodevelop

Scripts.Render is not working


I'm developing ASP.NET MVC Razor project using monodevelop 5.9.6 and I added all packages necessary for bundling (System.Web.Optimization), in BundleConfig I'm adding

bundles.add(ScriptBundle("~/bundles/jquery").Include("~/Scripts/jquery-{version}.js")); 

and others. In Global.asax.cs I'm calling

 BundleConfig.RegisterBundles(BundleTable.bundles); 

However in _Layout.cshtml

@Scripts.Render("~/bundles/jquery") 

is rendering as

<script src="/bundle/jquery?v=5GM9HLcujnDGm6SNVq0Es63_cXK2viQ4_nYEpm02Ls1"></script> 

when running, causing "Failed to load resource (404)" javascript error, because all jquery's files are not rendered as it should be.

I need to render all jquery files and style files.


Solution

  • It's a feature of Bundling and Minification. All of jquery and css file grouped into one file when you enable Bundling and Minification and it works in two conditions

    protected void Application_Start()
    {
      //Enabling Bundling and Minification
      BundleTable.EnableOptimizations = true;  
    }
    
    <compilation debug="false" targetFramework="4.0">
    

    IF you want each file render separately use compilation debug = "true" and BundleTable.EnableOptimizations = false;.

    But it's not a good practice when deploying code to production server.

    Why 404 : If you can share your rendering code for jquery and css file I can try why 404 error is coming.enter code here

    Thanks