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

后端 未结 12 1140
慢半拍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:34

    This might be a "hack" but you can use the built in Range attribute:

    [Display(Name = "Accepted Terms Of Service")]
    [Range(typeof(bool), "true", "true")]
    public bool Terms { get; set; }
    

    The only problem is the "warning" string will say "The FIELDNAME must be between True and true".

提交回复
热议问题