MVC3验证数据的注释? [英] MVC3 validation with data-annotation?

查看:137
本文介绍了MVC3验证数据的注释?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

时有可能使用一个数据注解的属性为dropdownlists是有效的,仅当用户选择从一个具有值O(零)不同的选项。
值为O(零)的选项是请选择一个帐户,这是默认选择。
我用[必需]属性来验证这个DropDownList的,但它不会有任何影响,因为,我怎么说,默认值为o选项(零) - 请选择一个帐户 - 选择

Is it possible to use a data-annotation attribute for dropdownlists to be valid, only if the user selects an option different from one with the value o (zero). The option with value o (zero) is "Please Select an account", which is selected by default. I used [Required] attribute to validate this dropdownlist, but it doesn't have any effect, because, how I said, by default the option with value o (zero)- "Please Select an account"- is selected.

推荐答案

是这样的:

[Range(1, int.MaxValue, ErrorMessage = "Please enter a value bigger than {1}")]
public int Value { get; set; }

这篇关于MVC3验证数据的注释?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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