如何通过属性验证一个日期在我的MVC模型中比另一个更大?

dog*_*lin 0 validation asp.net-mvc-4

我的模型代码中有以下内容

    [Required]
    public DateTime? PreferredShowDate1 { get; set; }

    public DateTime? PreferredShowDate2 { get; set; }

    public DateTime? PreferredShowDate3 { get; set; }
Run Code Online (Sandbox Code Playgroud)

现在,我想确保PreferredShowDate1 <PreferredShowDate2 <PreferredShowDate3并且3个日期中没有一个是相同的.

是否可以在型号代码中执行此操作?我能这样做吗?

//put in some code in attribute to compare preferredShowDate2 with preferredShowDate1      
[compare]
public DateTime? PreferredShowDate2 { get; set; }
Run Code Online (Sandbox Code Playgroud)

有任何想法吗?

Sli*_*sim 5

检查万无一失的验证

http://foolproof.codeplex.com/

使您可以访问greaterthan/lessthan验证属性以及许多有用的其他属性