在MVC 3.0中进行验证 [英] Validation in MVC 3.0

查看:76
本文介绍了在MVC 3.0中进行验证的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

朋友们,

我刚刚开始使用MVC 3.0.
请建议我如何在页面上应用验证.

我很困惑如何验证数据
以及什么级别
我已经尝试过google,但这完全超出了我的范围

1)模型级别验证
2)自定义验证
3)自我验证模型.
4)远程验证.
5)服务器端验证.

请帮帮我.
谢谢

Hi friends,

I have just started to use the MVC 3.0.
Please suggest me how we apply the validation on the page.

I am very confused how to validate the data
and what level
I have tried google but it was totally out of my scope

1)Model level validation
2)custom validation
3)self validation model.
4)Remote validation.
5)Server side validate.

Please help me.
Thanks

推荐答案

您可以做任何您想做的事情.您应该始终在服务器上进行验证,客户端验证很容易被黑客入侵.您也可以编写客户端代码.可以对视图模型进行注释,但只能注释到最高级别,因此您不能在视图模型内添加类,然后使用内置验证来验证该类的属性.对我来说,这就是永远不使用它的原因,但是您可以使用.

只需确保始终在服务器上进行验证,并使用方便的方法添加客户端验证即可.
You can do what ever you like. You should ALWAYS validate on the server, client side validation can be easily hacked. You can write client side code, too. It''s possible to annotate your viewmodel, but only to the top level, so you can''t have a class inside your viewmodel and then have the properties of that class be validated using the built in validation. For me, this is reason alone to never use it, but you can.

Just make sure you always validate on the server, and add client side validation for convenience, using whatever method you like.


这篇关于在MVC 3.0中进行验证的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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