JavaScript Error in Asp.Net MVC 4 Bundling

久未见 提交于 2019-12-23 11:45:13

问题


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?


回答1:


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




回答2:


Solution:

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



来源:https://stackoverflow.com/questions/15434692/javascript-error-in-asp-net-mvc-4-bundling

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!