Search code examples
c#asp.net-mvcscriptbundle

ScriptBundle - C# - add index in GET


how can I add GET to script in ScriptBundle ?

example:

 bundles.Add(new ScriptBundle("~/bundles/baseJs").Include(
                                        "~/Scripts/index.js"
));

and I want to call this script:

 "~/Scripts/index.js?1"

how can I do it ?


Solution

  • Bundles can be called at View(.cshtml) page like:

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

    Replace bundleName with your bundle name & it will render all js files in bundle on that page.

    Make sure you use render statement in start of html body.

    UPDATE: It's basic advantage of using bundling you can manage version of js with build. Just edit bundlename to add release number & voila all you client were forced to get bundle since it's name is different. We are doing like this.

    Earlier we need to manually minify js & added version number to files names too that was configured in web config files. That was painful, bundling is cherry on cake.