using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.ComponentModel.DataAnnotations; using System.ComponentModel; namespace Socrates.Objects { public class Engagement:IValidatableObject { public virtual int Id { get; set; } [Required] [DisplayFormat(DataFormatString = "{0:d}", ApplyFormatInEditMode = true)] [DisplayName("Start Date")] [DataType(DataType.Date)] public virtual DateTime? StartDate { get; set; } [Required] [DataType(DataType.Date)] [DisplayName("End Date")] [DisplayFormat(DataFormatString = "{0:d}", ApplyFormatInEditMode = true)] public virtual DateTime? EndDate { get; set; } public virtual Client Client { get; set; } public virtual Course Course { get; set; } public IEnumerable<ValidationResult> Validate(ValidationContext validationContext) { //string[] memberNames = new string[] { validationContext.MemberName }; if ((EndDate==null) || (StartDate == null)) { yield return new ValidationResult("StartDate or EndDate is null - something went terribly wrong!"); } if (EndDate < StartDate) { yield return new ValidationResult("Class cannot end before it starts", new[]{"Engagement.EndDate"}); } if (StartDate < DateTime.Now.Date) { yield return new ValidationResult("Start Date can not be in the past", new[] {"Engagement.StartDate"}); } if (EndDate > StartDate.Value.AddMonths(1)) { yield return new ValidationResult("You can not have a class longer than a month", new[]{"Engagement.EndDate"}); } } } }but then the validation happen only after I press Create button. I want them to be right away.