Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

MVC 4 BundleConfig not creating script references

I'm adding a few jQuery script files to my app using the bundleconfig.cs class.

bundles.Add(new ScriptBundle("~/bundles/jquery").Include(
                    "~/Scripts/jquery-{version}.js",
                    "~/Scripts/jquery-ui-{version}.js",
                    "~/Scripts/jquery.mCustomScrollbar.min.js",
                    "~/Scripts/jquery.mousewheel.min.js",
                    "~/Scripts/jtable/jquery.jtable.js"));

When I run my app and check the page source, only some of the script files are referenced:

<script src="/Scripts/jquery-1.10.2.js"></script>
<script src="/Scripts/jquery-ui-1.10.3.js"></script>
<script src="/Scripts/jtable/jquery.jtable.js"></script>
<script src="/Scripts/jquery-migrate-1.2.1.min.js"></script>

Why would this be happening? I can work around the issue by manually adding the script references directly to _Layout.cshtml, but that is hardly best practice.

like image 248
Swifty Avatar asked Jul 15 '13 09:07

Swifty


1 Answers

The .min part is already handled by MVC - it will automatically include .js files for Debug mode and .min.js files for Release mode.

Just download the unminified version of jquery.mCustomScrollbar.min.js and put it in your scripts directory, then reference it as: jquery.mCustomScrollbar.js

bundles.Add(new ScriptBundle("~/bundles/jquery").Include(
                    "~/Scripts/jquery-{version}.js",
                    "~/Scripts/jquery-ui-{version}.js",
                    "~/Scripts/jquery.mCustomScrollbar.js",
                    "~/Scripts/jquery.mousewheel.js",
                    "~/Scripts/jtable/jquery.jtable.js"));

MVC will then load the appropriate script for Debug/Release

like image 152
CodingIntrigue Avatar answered Sep 20 '22 08:09

CodingIntrigue