0

i have two properties in model class:

public DateTime StartDate { get; set; }
public DateTime EndDate { get; set; }

here,StartDate should be always less than EndDate is there any data annotation for this in asp.net mvc

user3801163
  • 105
  • 1
  • 1
  • 7
  • No built in attribute but you could look at using [foolproof](http://foolproof.codeplex.com/)'s `[LessThan]` attribute –  Apr 01 '15 at 10:17
  • http://stackoverflow.com/questions/3614076/net-mvc-custom-date-validator – Rohit Apr 01 '15 at 10:20

1 Answers1

2

There is the option to write your own custom attribute, as shown in this answer.

Another option is to use Foolproof (available from Nuget).

public class EventViewModel
{
    [Required]
    public string Name { get; set; }

    [Required]
    public DateTime Start { get; set; }

    [Required]
    [GreaterThan("Start")]
    public DateTime End { get; set; }
}
Community
  • 1
  • 1
devmb
  • 805
  • 6
  • 18
  • doesnt work with jQuery Date picker. it only works when input is changed but picker doesnt cause on input change event – Tommix Feb 12 '21 at 12:29