¿Qué referencia de jquery me falta?

I have a razor cshtml view that uses jquery. I get following error during certain user action.

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

When error happen, debugger breaks at MVCx.GetEditorByElement(b).unobtrusiveValidationAttributes[c+ this]}); from following line of code

 function(b,i){var d=a(b),f=d.parents("form")[0],c,e,g;if(!f)return;c=a(f).data("unobtrusiveValidation");c.options.rules[b.name]=e={};c.options.messages[b.name]=g={};a.each(this.adapters,function(){var c="data-val-"+this.name,i=MVCx.GetEditorByElement(b).unobtrusiveValidationAttributes[c],h={};if(i!==undefined){c+="-";a.each(this.params,function(){h[this]=MVCx.GetEditorByElement(b).unobtrusiveValidationAttributes[c + this]});this.adapt({element:b,form:f,message:i,params:h,rules:e,messages:g})}});jQuery.extend(e,{__dummy__:true});!i&&c.attachValidation()}

My theory is that error is caused because I may not have referece to certain JQuery file (missing some <script src="@Url.Content("~/ApplicationScripts/JQuery/jquery-1.4.4.min.js")" type="text/javascript"></script>.

Assuming its casued by missing jquery reference, one way of solving it is by adding all jquery references (obviously tedious). I wonder if there is better way of finding which jquery reference is actually needed.

ACTUALIZACIÓN This is how my references are setup right now

<script src="@Url.Content("~/ApplicationScripts/JQuery/jquery-1.4.4.min.js")" type="text/javascript"></script>
<script src="@Url.Content("~/ApplicationScripts/JQuery/jquery.unobtrusive-ajax.min.js")" type="text/javascript"></script>
<script src="@Url.Content("~/ApplicationScripts/JQuery/jquery.validate.min.js")" type="text/javascript"></script>
<script src="@Url.Content("~/ApplicationScripts/JQuery/jquery.validate.unobtrusive.min.js")" type="text/javascript"></script>

preguntado el 01 de febrero de 12 a las 22:02

Could you show your list of javascript references? -

updated question for my list of references. I wonder if the order of these files matters? -

The error is occuring when these libs are loaded or is there code being run? If there is code being run, is it run after document ready or when it compiles? Can we see that too? -

The order of the files certainly matters but I think you've got it right here. validate.unobtrusive almost certainly needs to come after the others. Also, have you tried a more recent version of jquery? 1.4.4 is a bit old; perhaps one of these libs needs a newer version? -

jquery, jquery.validatey jquery.validate.unobtrusive should be all you need. You might be barking up the wrong tree... I would try debugging using the unminified files. Also, as Kato suggests, try updating all those libraries with more recent versions. -

1 Respuestas

ASP.NET MVC 3 comes with jquery-1.5.1.js. Pareces estar usando jquery-1.4.4.min.js. I am not sure that the jquery.validate plugin and the other unobtrusive scripts are compatible with this version of jQuery. Try using the default scripts that are provided when creating a new application.

Respondido 02 Feb 12, 11:02

I can certainly try that. But my basic question is really how to findout which reference am I missing. In a C# project, if your API needs a certain assembly, you can just go to msdn, search for that API and that will tell you which assembly you need for reference. Is there any such mechansim in JQuery? - imak

@imak, no, there isn't such mechanism for javascript. - Darin Dimitrov

Thanks for your tip. Upgrading juqery to 1.5.1 solved my issue - imak

No es la respuesta que estás buscando? Examinar otras preguntas etiquetadas or haz tu propia pregunta.