<script src="/Content/Common/jquery-1.8.3.min.js"></script> <script src="/Content/Common/jquery-ui-1.10.1.custom.min.js"></script> <script src="/Content/Common/jquery.validate.js" type="text/javascript"></script> <script src="/Content/Common/jquery.unobtrusive-ajax.min.js" type="text/javascript"></script> <script src="/Content/Common/jquery.validate.unobtrusive.min.js" type="text/javascript"></script>
public class DateValidationCurrentLessThan : ValidationAttribute, IClientValidatable { protected override ValidationResult IsValid(object value, ValidationContext validationContext) { if (value != null) { var thisDate = (DateTime)value; if (thisDate > DateTime.Now) { var message = FormatErrorMessage(validationContext.DisplayName); return new ValidationResult(message); } } return ValidationResult.Success; } public IEnumerable<ModelClientValidationRule> GetClientValidationRules(ModelMetadata metadata, ControllerContext context) { ModelClientValidationRule dateGreaterThanRule = new ModelClientValidationRule(); dateGreaterThanRule.ErrorMessage = FormatErrorMessage(metadata.DisplayName); dateGreaterThanRule.ValidationType = "dategreaterthan"; // This is the name the jQuery adapter will use //"otherpropertyname" is the name of the jQuery parameter for the adapter, must be LOWERCASE! dateGreaterThanRule.ValidationParameters.Add("otherpropertyname", "2"); yield return dateGreaterThanRule; } }
data-val-dategreaterthan="The field is invalid." data-val-dategreaterthan-otherpropertyname="2"
var
This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)