How to handle Booleans/CheckBoxes in ASP.NET MVC 2 with DataAnnotations?

后端 未结 12 1141
慢半拍i
慢半拍i 2020-12-04 10:09

I\'ve got a view model like this:

public class SignUpViewModel
{
    [Required(ErrorMessage = \"Bitte lesen und akzeptieren Sie die AGB.\")]
    [DisplayName         


        
12条回答
  •  自闭症患者
    2020-12-04 10:35

    It's enough to add [RegularExpression]:

    [DisplayName("I accept terms and conditions")]
    [RegularExpression("True", ErrorMessage = "You must accept the terms and conditions")]
    public bool AgreesWithTerms { get; set; }
    

    Note - "True" must start with capital T

提交回复
热议问题