6

I want to use the Ajax.ActionLink Html helper therefore I need the jquery.unobtrusive-ajax.min.js library but IE is always showing this error:

Microsoft JScript runtime error: Unable to set value of the property 'unobtrusive': object is null or undefined

I've read that the solution is usage of jquery.validate.min.js and jquery.validate.unobtrusive.min.js but then I can't recognise the ajax call on server side.

abatishchev
  • 98,240
  • 88
  • 296
  • 433
sada
  • 584
  • 2
  • 8
  • 25

2 Answers2

21

I've read that the solution is usage of jquery.validate.min.js and jquery.validate.unobtrusive.min.js

No, those 2 script have nothing to do with jquery.unobtrusive-ajax.min.js. They are used for unobtrusive validation. For Ajax.* helpers all you need is jQuery and jquery.unobtrusive-ajax.min.js (included in THAT order).

So for unobtrusive AJAX you need:

<script src="@Url.Content("~/Scripts/jquery-1.5.1.min.js")" type="text/javascript"></script>
<script src="@Url.Content("~/Scripts/jquery.unobtrusive-ajax.min.js")" type="text/javascript"></script>

If you want to use unobtrusive validation you could also include the 2 scripts afterwards (in THAT order):

<script src="@Url.Content("~/Scripts/jquery.validate.min.js")" type="text/javascript"></script>
<script src="@Url.Content("~/Scripts/jquery.validate.unobtrusive.min.js")" type="text/javascript"></script>

Another very important thing that you should make sure is that you have removed absolutely any traces of Microsoft*.js scripts from your project. Those scripts are obsolete and starting from ASP.NET MVC 3 are no longer used by default. Also make sure that youhave enabled unobtrusive AJAX in your web.config, otherwise the system will fallback to the legacy Microsoft ajax scripts:

<appSettings>
    <add key="webpages:Version" value="1.0.0.0"/>
    <add key="ClientValidationEnabled" value="true"/>
    <add key="UnobtrusiveJavaScriptEnabled" value="true"/>
</appSettings>
Darin Dimitrov
  • 1,023,142
  • 271
  • 3,287
  • 2,928
  • 1
    Thank you for your response. I use these: jquery-1.7.2.min.js, jquery.unobtrusive-ajax.min.js, jquery.validate.min.js, jquery.validate.unobtrusive.min.js, jquery-ui-1.8.20.min.js and I've set the web.config but how I can eliminate this error: Microsoft JScript runtime error: Unable to set value of the property 'unobtrusive': object is null or undefined? Because as I know it is due to jquery.unobtrusive-ajax.min.js. – sada Jul 04 '12 at 10:29
  • 2
    Please also note that jquery.unobtrusive-ajax.js is not compatible with any jquery version higher than 1.8.3. jquery 1.8.3 is the latest version that is compatible with jquery.unobtrusive-ajax.js. – monstro Feb 13 '13 at 14:26
  • 1
    http://stackoverflow.com/questions/14391867/unobtrusive-ajax-stopped-working-after-update-jquery-to-1-9-0 – monstro Feb 13 '13 at 14:27
2

This is an old post, but if anyone needs the latest on unobtrusive ajax, it can be found here:

http://nuget.org/packages/Microsoft.jQuery.Unobtrusive.Ajax/3.0.0-beta2

There are other stable versions that work on latest jquery lib.

Ostati
  • 4,623
  • 3
  • 44
  • 48