ASP.NET MVC3和服务器端验证 [英] ASP.NET MVC3 and server side validation

查看:99
本文介绍了ASP.NET MVC3和服务器端验证的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

假设用户已禁用JavaScript,因此客户端验证不能在MVC3工作。

Suppose a user has javascript disabled and thus client side validation doesn't work in MVC3.

什么是实现服务器端验证,所以当用户试图处理数据的方式不好?该验证消息仍然显示的最佳方式

What is the best way to implement server side validation so that validation messages are still displayed when the user tries to handle data in an inappropriate way?

谢谢!

编辑:

显然,这是怎么回事,因为我使用的是EF生成的模型和他们使用的属性setterStructuralObject.SetValidValue的方法。这将导致异常MVC之前被抛出可以验证模型。

Apparently it's happening because I'm using EF generated models and they use "StructuralObject.SetValidValue" methods in property setters. This results in an exception being thrown before MVC can validate the model.

我试图找到一种方法,现在来规避这一权利...

I'm trying to find a way to circumvent this right now...

推荐答案

那么,你应该总是使用客户端和服务器端验证。如果标记的模型验证特性在服务器端和客户端验证应该工作得很好。

Well, you should always use client side and server side validation. If you mark the models with validation attributes both the server-side and client-side validation should work just fine.

我相信你已经看到了这一点:的http:// bradwilson.typepad.com/blog/2010/10/mvc3-unobtrusive-validation.html

I am sure you have seen this: http://bradwilson.typepad.com/blog/2010/10/mvc3-unobtrusive-validation.html

只要确保在服务器端验证的行动检查模型的状态一次,一切都将工作的伟大。

Just be sure to check model state once in the action for the server-side validation and everything will work great.

这篇关于ASP.NET MVC3和服务器端验证的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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