Created
February 29, 2016 00:35
-
-
Save dejanvasic85/117e0953bd74a1dd5be7 to your computer and use it in GitHub Desktop.
Custom validation attribute to ensure a checkbox is checked
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/// <summary> | |
/// This is used on mostly checkboxes that ensure that they are ticked such as terms and conditions. | |
/// </summary> | |
public class MustBeTrueAttribute : ValidationAttribute | |
{ | |
public override bool IsValid(object value) | |
{ | |
if (value == null) return false; | |
if (value.GetType() != typeof(bool)) return false; | |
return (bool)value; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment