开发者

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

开发者 https://www.devze.com 2023-01-08 02:47 出处:网络
How can I use DataAnnotations to validate that at least one of these fields are filled in? public string Name { get; set; }

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

精彩评论

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