如何强制形式的客户端验证或$。阿贾克斯()之前 [英] How to force form client-side validation in or before $.ajax()

查看:109
本文介绍了如何强制形式的客户端验证或$。阿贾克斯()之前的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个表格,不引人注目的验证已启用。默认情况下,提交方法客户端验证被触发(如果您有任何错误)的形式如下:

I have a form and unobtrusive validations are enabled. By default in submit method client side validation gets triggered and (if you have any errors) the form looks like this:

验证甚至发生之前的任何数据被发送到服务器。

The validation happens even before any data gets sent to the server.

现在,如果你想用$就法这种行为是行不通的。客户端验证不起作用。您必须手动检查所有字段在JavaScript,失去DataAnnotations的所有美景。

Now this behavior doesn't work if you want to use $.ajax method. Client side validation doesn't work. You have to manually check all the fields in your javascript, losing all the beauty of DataAnnotations.

有没有更好的解决办法?我可能已经使用jQuery的提交(),但我想它没有像回调的 $。阿贾克斯

Is there any better solution? I could've use jquery's submit() but I guess it doesn't have callback like $.ajax.

推荐答案

呵呵...

if (form.valid()) // do submit

这篇关于如何强制形式的客户端验证或$。阿贾克斯()之前的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆