Chris Chris - 1 month ago 10
Javascript Question

Uncaught TypeError: Cannot set property 'unobtrusive' of undefined

I am using the latest MVC framework and bundles.

The default "jqueryval" bundle that MVC creates is causing a javascript error

The scripts on my page are output like so

<!-- In head -->
<script src="/Scripts/modernizr-2.6.2.js"></script>
<script src="/Scripts/jquery-2.0.2.js"></script>
<script type="text/javascript" src="http://maps.google.com/maps/api/js?sensor=false"></script>
<script type="text/javascript" src="/Content/Misc.js"></script>


<!-- Bottom of doc -->
<script src="/Scripts/jquery.unobtrusive-ajax.js"></script>
<script src="/Scripts/jquery.validate.unobtrusive.js"></script>


My Bundle:

bundles.Add(new ScriptBundle("~/bundles/jqueryval").Include(
"~/Scripts/jquery.validate*",
"~/Scripts/jquery.unobtrusive*"));


What is going wrong?

Ian Ian
Answer

In your bundle, you set it to include jquery.validate* and jquery.unobtrusive*, which would normally work. But if you look at your output, not all files that should be there are there. The point is that jquery.unobtrusive.validate requires jquery.validate to be included (which, as you can see, is not, by your output). Apparently, the files aren't actually available in your project, and therefore aren't found by the bundler. Make sure to have all necessary files in your project so your bundler can find them and output them.

Comments