使用 jQuery 验证 ASP.NET MVC 3.0 AjaxForm 时出现错误
尝试使用此解决方案使用 jQuery 验证 AjaxForm ASP.Net MVC Ajax 表单验证,但我收到错误:未捕获的异常:TypeError:无法将 '$('MyFrom').validate()' 转换为对象
我的来源:
@using (Ajax.BeginForm("MyFromAction", "Something", null, new AjaxOptions() { OnBegin = "onBeginMyFrom", OnFailure = "onFailureMyFrom", OnSuccess = "onSuccessMyFrom" }, new { @id = "MyFrom" }))
{
}
我的表单是工作正常并发布到服务器,但在我使用 jQuery 验证后,我收到上面的错误。
有什么想法吗?
更新: 我没有提到我正在使用 MVCContrib FluentHtml。
MVCContrib 需要这个 http://weblogs.asp.net/srkirkland/archive/2011/03/08/adding-unobtrusive-validation-to-mvccontrib-fluence-html.aspx 以获得不显眼的验证工作。
MvcContrib 是否会在下一个版本中默认支持 Unobtrusive 验证?
Trying to use this solution to validate AjaxForm ASP.Net MVC Ajax form with jQuery validation but i am getting error: Uncaught exception: TypeError: Cannot convert '$('MyFrom').validate()' to object
My from:
@using (Ajax.BeginForm("MyFromAction", "Something", null, new AjaxOptions() { OnBegin = "onBeginMyFrom", OnFailure = "onFailureMyFrom", OnSuccess = "onSuccessMyFrom" }, new { @id = "MyFrom" }))
{
}
My form was working correctly and posting to the server, but after i use jQuery validation i am getting error above.
Any ideas?
UPDATE:
I didn't mention that i am using MVCContrib FluentHtml.
MVCContrib required this http://weblogs.asp.net/srkirkland/archive/2011/03/08/adding-unobtrusive-validation-to-mvccontrib-fluent-html.aspx to get Unobtrusive validation work.
Is MvcContrib will support Unobtrusive validation in the next release by default?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您正在查看的答案与 ASP.NET MVC 的早期版本有关。在 ASP.NET MVC 3 中,客户端验证是使用 jquery 验证插件执行的,并且是在不显眼的情况下完成的。您不需要任何代码。因此,第一件事是确保您已包含正确的脚本:
然后在 web.config 中启用不显眼的 javascript 和验证:
现在您可以让 AJAX 表单正常运行:
表单将在客户端检查验证错误并且在修复之前不会提交。
The answer you are looking at was related to a previous version of ASP.NET MVC. In ASP.NET MVC 3 client validation is performed using the jquery validate plugin and it is done in an unobtrusive matter. You don't need any code for this. So the first thing is to make sure that you have included the proper scripts:
then that unobtrusive javascript and validation are enabled in web.config:
Now you can have your AJAX form behave properly:
The form will check for validation errors at the client side and it will not be submitted until they are fixed.