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.
UPDATE
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>
ASP.NET MVC 3 comes with
jquery-1.5.1.js. You seem to be usingjquery-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.