0

I have followed several tutorials about microsoft unobtrusive Ajax Nuget package.

They say I should add this script inclusion in my main layout:

<script src="~/Scripts/jquery.unobtrusive-ajax.js"></script> 

I got this js error:

ReferenceError: Can't find variable: jQuery - jquery.unobtrusive-ajax.js:189

It works fine if I include by hand a script src tag for jquery. I am wondering why tutorials does not say to include jquery js file.

Bob5421
  • 7,757
  • 14
  • 81
  • 175

1 Answers1

0

The 'unobtrusive ajax' lib you want to use has a dependency on jQuery. So jQuery itself must be added to the page, before the jquery.unobtrusive-ajax.js is loaded.

If the tutorials are open source / wiki / git based, maybe you can update them.

David De Sloovere
  • 3,415
  • 2
  • 24
  • 27
  • Thanks Should I check Web API at the project creation for jquery unobustrive Ajax ? – Bob5421 Sep 14 '16 at 13:34
  • And do you know If there is a way to include jquery without typing the version number (in script tag) ? – Bob5421 Sep 14 '16 at 13:34
  • 1
    You'll want to reference a specific version. That way your application won't suddenly break when a new version of jQuery is released. If you use the bundling that comes with asp.net mvc, you can use "~/scripts/jquery-{version}.js" and the bundler will figure out what version you have in your project. With this technique, you are still in control of the version that is installed in your project (via nuget package most likely). This should be used in the default project template. – David De Sloovere Sep 15 '16 at 12:23
  • Thanks. Do you know what is the difference between and – Bob5421 Sep 15 '16 at 17:01
  • You can't do the {version} trick in the view directly. That goes into the bundle config. See halfway this page http://www.asp.net/mvc/overview/performance/bundling-and-minification – David De Sloovere Sep 16 '16 at 10:41