title: Custom Validation Attributes: Comparing two properties in the same model
body: <p>Is there a way to create a custom attribute in ASP.NET Core to validate if one date property is less than other date property in a model using <em><code>ValidationAttribute</code></em>.</p>
  
  <p>Lets say I have this:</p>
  
  <pre><code>public class MyViewModel 
  {
      [Required]
      [CompareDates]
      public DateTime StartDate { get; set; }
  
      [Required]
      public DateTime EndDate { get; set; } = DateTime.Parse("3000-01-01");
  }
  </code></pre>
  
  <p>I am trying to use something like this:</p>
  
  <pre><code>    public class CompareDates : ValidationAttribute
  {
      public CompareDates()
          : base("") { }
  
      public override bool IsValid(object value)
      {
          return base.IsValid(value);
      }
  
  }
  </code></pre>
  
  <p>I found other SO post that proposes to use another library, But I prefer to stick with ValidationAttribute if that was doable. </p>