开发者

MVC DataAnnotations - Require at least one field in a group to be filled

How can I use DataAnnotations to validate that at least one of these fields are filled in?

    public string Name { get; set; }
    public string State { get; set;}
    public string Zip { get;开发者_如何学Python set;}


To do it using DataAnnotations you will need to make a custom attribute because as far as I know there is no built in attribute that will handle this.

To get you started, when you start a new MVC project there is a class called "PropertiesMustMatchAttribute" that is applied at the class level. You could base it off that without much difficulty

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜