3

例子:

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; }
}

我想拥有至少一个电话号码,但我不在乎是哪一个。输入多个电话号码也应该是可能的。

有没有一种干净的方法可以做到这一点?还是我必须自己编写验证?

4

1 回答 1

4

是的,您必须自己编写验证。采用IValidatableObject

于 2012-08-29T08:56:14.363 回答