无法显示来自mvc模型的验证错误消息

本文关键字:验证 错误 消息 模型 mvc 显示 | 更新日期: 2023-09-27 18:26:16

我的文件按的顺序排列

 <script src="~/Content/js/jquery.min.js"></script>
 <script src="~/Content/js/jquery.validate.unobtrusive.js"></script>
 <script src="~/Content/js/jquery.unobtrusive-ajax.min.js"></script>
 <script src="~/Content/js/jquery.validate.min.js"></script>
 <script src="~/Content/js/jquery.validate.mvc.js"></script>
 <script src="~/Content/js/responsive-table-ul-main.js"></script>
 <script src="~/Content/js/bootstrap.min.js"></script>

我在"无法设置未定义的属性'unsobtrust'"页面上收到此错误。当我提交按钮或加载页面时,控制台中出现此错误

无法显示来自mvc模型的验证错误消息

查看jquery验证的bower文件不引人注目:https://github.com/aspnet/jquery-validation-unobtrusive/blob/master/bower.json

很明显,它依赖于jquery.validate脚本。因此,您需要将它们放在html中的jquery.validation.uno唐突之前,如下所示:

 <script src="~/Content/js/jquery.min.js"></script>
 <script src="~/Content/js/jquery.validate.min.js"></script>
 <script src="~/Content/js/jquery.validate.mvc.js"></script>
 <script src="~/Content/js/jquery.validate.unobtrusive.js"></script>
 <script src="~/Content/js/jquery.unobtrusive-ajax.min.js"></script>
 <script src="~/Content/js/responsive-table-ul-main.js"></script>
 <script src="~/Content/js/bootstrap.min.js"></script>