ASP.NET MVC - 用于客户端验证的数据注释
如果 ASP.NET MVC 应用程序使用数据注释...
<%= Html.ValidationSummary("Things broke...") %>
<% Html.EnableClientValidation(); %>
并且我们将其发布到服务器。我们是否仍然会点击该操作,检查 ModelState.IsValid 并返回到带有验证错误的原始视图。如果我们(通过帖子)访问服务器,它是否仍被视为客户端验证?
If an ASP.NET MVC application using Data Annotations...
<%= Html.ValidationSummary("Things broke...") %>
<% Html.EnableClientValidation(); %>
And we post to the server. Won't we still hit the action, check the ModelState.IsValid and come back to the original view with the validation error. Is it still considered client side validation if we're hitting the server (via a post)?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
不,你刚才所说的不被视为客户端验证。
客户端验证被认为是验证浏览器(客户端)中表单的任何内容,通常使用 JavaScript。将帖子发送到服务器 (ASP.net) 后,您就处于服务器端验证模式。
我相信您真正要问的是新的 asp.net mvc 2.0 验证是否是客户端。
EnableClientValidation 使您的数据注释模型能够使用 jquery 验证插件来执行真正的客户端验证。它不应该回发到服务器来进行验证,但是当它回发时,它可能也会在服务器上进行验证,因为客户端验证不是 100% 可靠。
No, what you just said is not considered client side validation.
Client side validation is considered anything that validates the form in the browser (client), usually with JavaScript. Once the post is sent to the server (ASP.net), then you are in server side validation mode.
I believe what you are really asking though is whether the new asp.net mvc 2.0 validation is client side or not.
EnableClientValidation enables your data annotated models to use the jquery validate plugin to do true client side validating. It should not be posting back to the server to do the validating, but when it does post back it will probably validate on the server as well since client side validation is not 100% reliable.
是的,这就是服务器端验证。如果您在客户端进行验证并避免在任何字段无效时发布表单,那么它就是客户端验证。
Yes, that would be server side validation. If you do the validation on the client side and avoid the form to be posted when any of the fields are invalid, then it's client side validation.
如果您添加这些库,它将负责客户端验证。
这些库将生成用于验证的 JavaScript 代码。
但为此,您需要使用 Dataannotations
这里是示例
If you add these libraries it will take care of the client validation.
These libraries will generate the javascript code for validation.
But for this you need to use Dataannotations
Here is an example about it