[英]How can I require one of multiple properties?
Example: 例:
public class Person
{
[Required]
[DisplayName("Firstname")]
public string firstname { get; set; }
[Required]
[DisplayName("Lastname")]
public string lastname{ get; set; }
// I want to require at least one of these 3 phones
[DisplayName("Mobile Phone")]
public string mobilephone { get; set; }
[DisplayName("Work Phone")]
public string workphone { get; set; }
[DisplayName("Home Phone")]
public string homephone { get; set; }
}
I want to have at least one phone number, but I don't care which one. 我想至少有一个电话号码,但我不在乎哪一个。 Entering more than one phone number should also be possible.
也应该输入多个电话号码。
Is there a clean way to do this? 有干净的方法吗? Or do I have to write the validation myself?
或者我是否必须自己编写验证?
Yes, you have to write the validation yourself. 是的,您必须自己编写验证。 Use
IValidatableObject
使用
IValidatableObject
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.