5

When I use the below Bundling in MVC 4, my App gets several JavaScript errors,such as 'jQuery undefined'

        bundles.Add(new ScriptBundle("~/bundles/jquery").Include(
                    "~/Scripts/jquery-{version}.js",
                    "~/Scripts/jquery-ui-{version}.js",
                    "~/Scripts/jquery.unobtrusive*",
                    "~/Scripts/jquery.validate*"));

But when I use the below approach, my App works without JavaScript errors:

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

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

        bundles.Add(new ScriptBundle("~/bundles/jquery3").Include(
                    "~/Scripts/jquery.unobtrusive*"));

        bundles.Add(new ScriptBundle("~/bundles/jquery3").Include(
                    "~/Scripts/jquery.validate*"));

My Question: what is the problem?

5
  • In debug mode, are the individual script tags added in the correct order? Commented Mar 15, 2013 at 14:24
  • 2
    Sounds like the scripts are being included in the wrong order. This answer suggests it might be the version of the Web Optimization Framework that you're using: stackoverflow.com/a/11995916/1043198 Commented Mar 15, 2013 at 14:29
  • @AntP very thanks, i updated to Microsoft.AspNet.Web.Optimization version 1.1.0-Beta1 now my app works correctly. Commented Mar 15, 2013 at 15:27
  • @user197508 I've posted my response as an answer :) Commented Mar 15, 2013 at 15:30
  • @AntP thanks;) i accepted your answer with +1 vote. Commented Mar 15, 2013 at 15:49

2 Answers 2

3

This is caused by your scripts being included in the wrong order. You should ensure that your version of the Web Optimization Framework is up-to-date. This answer provides further details:

https://stackoverflow.com/a/11995916/1043198

And the NuGet package:

http://nuget.org/packages/Microsoft.AspNet.Web.Optimization

Sign up to request clarification or add additional context in comments.

Comments

2

Solution:

I updated Microsoft.AspNet.Web.Optimization from version 1.0.0 to version 1.1.0-Beta1 now my app works correctly.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.