Script and Styles render in ASP.NET MVC

522 Views Asked by At

I'm trying to minify some files with BundleConfig, everything looks to be ok, the problem is when I try to use @Styles.Render and @Scripts.Render, when I use those renders on the HTML I get a loop of errors and of course the page doesn't load, I think the render can't find the virtual path.

So my question is, what else should I do or what I'm missing on my setup for the HTML to recognize virtual bundle files?


Here is the error message trace on the loop, this loops indefinitely:

Exception thrown: 'System.ArgumentException' in mscorlib.dll
Exception thrown: 'System.Net.Sockets.SocketException' in System.dll
Exception thrown: 'System.IO.IOException' in System.dll
Exception thrown: 'System.Net.WebException' in System.dll
Exception thrown: 'System.Net.WebException' in System.dll
Exception thrown: 'System.Net.WebException' in System.dll
Exception thrown: 'System.Net.WebException' in System.dll
Exception thrown: 'System.Net.WebException' in System.dll
Exception thrown: 'System.Net.WebException' in System.dll
The thread 0x3ee8 has exited with code 0 (0x0).

This is my setup at the moment:

BundleConfig

    public static void RegisterBundles(BundleCollection bundles)
    {
        bundles.Add(new ScriptBundle("~/bundles/js").Include(
                    "~/Assets/dist/js/app.js",
                    "~/Assets/dist/js/main.js"));

        bundles.Add(new StyleBundle("~/Style/css").Include(
                  "~/Assets/dist/css/app.css",
                  "~/Assets/dist/css/main.css"));

        // This is a test, I read that Bundle can be use instead of ScriptBundle/StyleBundle
        // Didn't work
        bundles.Add(new Bundle("~/Content/css").Include(
                  "~/Assets/dist/css/app.css",
                  "~/Assets/dist/css/main.css"));


        // This is because I'm in DEBUG mode 
        BundleTable.EnableOptimizations = true;
    }

Global.asax.cs

    protected void Application_Start(object sender, EventArgs e)
    {
        . . .
        BundleConfig.RegisterBundles(BundleTable.Bundles);
    }

base.cshtml

@using System.Web.Optimization;

. . .

@Styles.Render("~/Content/css")

. . .

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

I also had try this in my web.config, but I removed it since is a redundant reference:

<add namespace="System.Web.Optimization"/>
0

There are 0 best solutions below