Asp.net-mvc – Microsoft JScript runtime error: ‘jQuery’ is undefined

asp.net-mvcasp.net-mvc-3

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

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.

The SO post Updated JQuery – get Microsoft JScript runtime error: 'jQuery' is undefined seems 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.

Here is my packages.config file:

<?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>

Best Solution

This means that your script reference to jQuery*.js is broken, when another script tires to call jQuery this error is thrown.

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>

If you have updated jQuery using the package manager, the version number in the reference needs to be updated. "~/Scripts/jquery-<version>.min.js"

  1. Make sure the path is valid.
  2. Make sure its the first script referenced.
  3. Test using Chrome/IE/FireFox debug tools
Related Question