Sometimes you really need a user to put a tick in a checkbox, for instance when submitting a registration form where acceptance of terms and conditions is required.
Here's how you do it in ASP.NET MVC, via a custom ValidationAttribute that decorates a property of your ViewModel:
public class MustBeTrueAttribute : ValidationAttribute { public override bool IsValid(object value) { return value is bool && (bool)value; } }
[MustBeTrue(ErrorMessage = "Please check the box before continuing!")] public bool TandCs { get; set; }
Job done :)
;
Comments
Please consider what you post!
Chillax if you're angry.