I created custom validation in MVC model to check whether EndDate field is greater than StartDate. Like this:
public class ViewModel: IValidatableObject
{
[Required]
public DateTime StartDate { get; set; }
[Required]
public DateTime EndDate { get; set; }
public IEnumerable<ValidationResult> Validate(ValidationContext validationContext)
{
if (EndDate < StartDate)
{
yield return
new ValidationResult(errorMessage: "EndDate must be greater than StartDate",
memberNames: new[] { "EndDate" });
}
}
}
thanks to this post for showing me how do that.
But this code works in Server side only. It doesn't validates before submitting the form. Means it doesn't show any error message when i put
@Html.ValidationMessageFor(x => x.EndDate)
Can any one help me to make this validation possible in the client side using jquery unobtrusive validation?