未捕获的类型错误:不能设置未定义的属性“unobtrusive”

时间:2022-08-24 13:55:15

I am using the latest MVC framework and bundles.

我正在使用最新的MVC框架和包。

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

MVC创建的默认“jqueryval”绑定会导致javascript错误

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?

什么错了吗?

2 个解决方案

#1


8  

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.

在您的包中,您将它设置为包含jquery。验证*和jquery。不引人注目的*,这通常会起作用。但是如果你看你的输出,不是所有的文件都在那里。关键是,jquery.n。验证需要jquery。验证被包含(如您所见,它不是由您的输出决定的)。显然,这些文件在您的项目中实际上是不可用的,因此bundler无法找到这些文件。确保您的项目中有所有必要的文件,这样您的bundler可以找到并输出它们。

#2


0  

I found that replacing the wildcards with full js script name worked.

我发现用完整的js脚本名替换通配符是可行的。

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

#1


8  

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.

在您的包中,您将它设置为包含jquery。验证*和jquery。不引人注目的*,这通常会起作用。但是如果你看你的输出,不是所有的文件都在那里。关键是,jquery.n。验证需要jquery。验证被包含(如您所见,它不是由您的输出决定的)。显然,这些文件在您的项目中实际上是不可用的,因此bundler无法找到这些文件。确保您的项目中有所有必要的文件,这样您的bundler可以找到并输出它们。

#2


0  

I found that replacing the wildcards with full js script name worked.

我发现用完整的js脚本名替换通配符是可行的。

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