c# - .Net - DataAnnotations - Validate 2 dependent DateTime -
let got following classes:
public class post  {     public date begindate { get; set; }      [validate2date(begindate, enddate, errormessage = "end date have occurs after begin date")]     public date enddate { get; set; } }  public class validate2dates : validationattribute {     public validate2dates(datetime a, datetime b)     { ... }      public override bool isvalid(object value)     {         // compare date , return false if b <     } }   my problem how use custom validate2dates attribute because can't that:
[validate2date(begindate, enddate, errormessage = "end date have occurs before begin date")]   i got following error:
an object reference required non-static field, method, or property '...post.begindate.get' c:...\post.cs
you can't use attribute that. attribute parameters restricted constant values.
imo better solution provide method on class implements check , can called through business logic validation interface of liking.
Comments
Post a Comment