使用来自不同视图模型的AssertThat使用ExpressiveAnnotations进行验证

时间:2016-06-10 06:35:42

标签: c# asp.net-mvc expressiveannotations

我正在尝试使用ExpressiveAnnotations来验证我的表单。我有两个视图模型,其中第二模型依赖于第一模型。这可以使用这个库吗?

谢谢。

public class ViewModel
    {    
        [Required]
        [Column(TypeName = "date")]
        public DateTime? Start { get; set; }

        [AssertThat("End >= Start", ErrorMessage = "You cannot set end date before the start of leave.")]
        [Required]
        [Column(TypeName = "date")]
        [Display(Name = "End ")]
        public DateTime? End { get; set; }
    }


public class ViewModel1
{
    [AssertThat("Date1 < Start", ErrorMessage = "Start cannot be before Date1.")]
    [AssertThat("Date1 >= End", ErrorMessage = "Start cannot be after Date1.")]
    [Required]
    [Display(Name = "Date1 ")]
    [Column(TypeName = "date")]
    public DateTime? Date1 { get; set; }
}

0 个答案:

没有答案