I\'ve got a view model like this:
public class SignUpViewModel
{
[Required(ErrorMessage = \"Bitte lesen und akzeptieren Sie die AGB.\")]
[DisplayName
My Solution is as follows (it's not much different to the answers already submitted, but I believe it's named better):
///
/// Validation attribute that demands that a boolean value must be true.
///
[AttributeUsage(AttributeTargets.Property, AllowMultiple = false, Inherited = false)]
public class MustBeTrueAttribute : ValidationAttribute
{
public override bool IsValid(object value)
{
return value != null && value is bool && (bool)value;
}
}
Then you can use it like this in your model:
[MustBeTrue(ErrorMessage = "You must accept the terms and conditions")]
[DisplayName("Accept terms and conditions")]
public bool AcceptsTerms { get; set; }