asp.net-mvc Microsoft JScript 运行时错误:“jQuery”未定义
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/11905075/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Microsoft JScript runtime error: 'jQuery' is undefined
提问by bernie2436
I am an ASP MVC 3 noobie working my way through the music store tutorial http://www.asp.net/mvc/tutorials/mvc-music-store/mvc-music-store-part-5
我是一名 ASP MVC 3 noobie,正在学习音乐商店教程http://www.asp.net/mvc/tutorials/mvc-music-store/mvc-music-store-part-5
I have successfully added a StoreManager controller with Add/Edit/Delete operations. The controller works--I am able to perform these operations. But midway thru, visual studio shows pop ups that say "Microsoft JScript runtime error: 'jQuery' is undefined." I just ignore these errors and everything runs fine.
我已经成功地添加了一个带有添加/编辑/删除操作的 StoreManager 控制器。控制器工作——我能够执行这些操作。但中途,visual studio 显示弹出窗口,内容为“Microsoft JScript 运行时错误:'jQuery' 未定义”。我只是忽略这些错误,一切正常。
The SO post Updated JQuery - get Microsoft JScript runtime error: 'jQuery' is undefinedseems to imply that there might be a problem with my packages.config file. Is there something I need to fix in this file to make this error go away? How can I be sure that jQuery is installed and properly hooked up to MVC3/Visual Studio? I assume that jQuery was included when installed SP1 with the MVC 3 components.
SO post Updated JQuery - get Microsoft JScript runtime error: 'jQuery' is undefined似乎暗示我的packages.config文件可能有问题。是否需要在此文件中修复某些内容才能消除此错误?如何确定 jQuery 已安装并正确连接到 MVC3/Visual Studio?我假设在安装带有 MVC 3 组件的 SP1 时包含了 jQuery。
Here is my packages.config file:
这是我的packages.config文件:
<?xml version="1.0" encoding="utf-8"?>
<packages>
<package id="jQuery" version="1.5.1" />
<package id="jQuery.vsdoc" version="1.5.1" />
<package id="jQuery.Validation" version="1.8.0" />
<package id="jQuery.UI.Combined" version="1.8.11" />
<package id="EntityFramework" version="4.1.10331.0" />
<package id="Modernizr" version="1.7" />
</packages>
回答by Ed Charbeneau
This means that your script reference to jQuery*.js is broken, when another script tires to call jQuery this error is thrown.
这意味着您对 jQuery*.js 的脚本引用已损坏,当另一个脚本厌倦调用 jQuery 时,将抛出此错误。
Look at your markup usually in _Layout.cshtml and find the <script>references. There should be one similar to <script src="@Url.Content("~/Scripts/jquery-1.5.1.min.js")" type="text/javascript"></script>
通常在 _Layout.cshtml 中查看您的标记并找到<script>引用。应该有一个类似的<script src="@Url.Content("~/Scripts/jquery-1.5.1.min.js")" type="text/javascript"></script>
If you have updated jQuery using the package manager, the version number in the reference needs to be updated. "~/Scripts/jquery-<version>.min.js"
如果您使用包管理器更新了 jQuery,则需要更新参考中的版本号。 "~/Scripts/jquery-<version>.min.js"
- Make sure the path is valid.
- Make sure its the first script referenced.
- Test using Chrome/IE/FireFox debug tools
- 确保路径有效。
- 确保它是引用的第一个脚本。
- 使用 Chrome/IE/FireFox 调试工具进行测试
回答by CSharp
If you have master page, can you check whether any other jQuery reference is added to the content page or not? Same JQuery reference should not be duplicated.
如果您有母版页,您能否检查是否将任何其他 jQuery 引用添加到内容页?不应重复相同的 JQuery 引用。

