Fresh MVC 3 project giving me wierd unobtrusive check script error

I just created a new MVC 3 project and updated all installed packages using the package manager, however I get the following error:

Microsoft JScript runtime error: Unable to set property to “unobtrusive”: object is null or undefined

Here is the relevant code:

<!DOCTYPE html>

<html lang="en">
    <head>
        <meta charset="utf-8" />
        <title>@ViewBag.Title</title>

        <link href="@Url.Content("~/Content/Reset.css")" rel="stylesheet" type="text/css" />
        <link href="@Url.Content("~/Content/Site.css")" rel="stylesheet" type="text/css" />

        <script src="@Url.Content("~/Scripts/modernizr-1.7.min.js")" type="text/javascript"></script>

        <script src="@Url.Content("~/Scripts/jquery-1.7.2.min.js")" type="text/javascript"></script>
        <script src="@Url.Content("~/Scripts/jquery-ui-1.8.20.min.js")" type="text/javascript"></script>

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

    <body>
        @RenderBody()
    </body>
</html>

A javascript snippet from the area in which the error occurs:

$jQval.unobtrusive = {
        adapters: [],

        parseElement: function (element, skipAttach) {
            /// <summary>
            /// Parses a single HTML element for unobtrusive validation attributes.
            /// </summary>
            /// <param name="element" domElement="true">The HTML element to be parsed.</param>
            /// <param name="skipAttach" type="Boolean">[Optional] true to skip attaching the
            /// validation to the form. If parsing just this single element, you should specify true.
            /// If parsing several elements, you should specify false, and manually attach the validation
            /// to the form when you are finished. The default is false.</param>
            var $element = $(element),
                form = $element.parents("form")[0],
                valInfo, rules, messages;

            if (!form) {  // Cannot do client-side validation without a form
                return;
            }...

Can someone tell me why this error is happening and how can I fix it? Am I just skipping the link to the required script?

Thanks, Alex.

+3
source share
2 answers

You must turn on jquery.validate.jsbeforejquery.validate.unobtrusive.js

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

JQuery Validate script

+2

All Articles