我在这里问类似的问题,但是在这个问题中我使用了另一个实现,正是这种方式下面的代码显示了我的实现:
模型:
public class Department {
public long Id { get; set; }
[IsDateAfter("Date2", true, ErrorMessage = "O My")]
public DateTime Date1 { get; set; }
public DateTime Date2 { get; set; }
public string Name1 { get; set; }
public string Name2 { get; set; }
}
Run Code Online (Sandbox Code Playgroud)
自定义验证器:
public sealed class IsDateAfter : ValidationAttribute, IClientValidatable {
private readonly string testedPropertyName;
private readonly bool allowEqualDates;
public IsDateAfter(string testedPropertyName, bool allowEqualDates = false)
{
this.testedPropertyName …Run Code Online (Sandbox Code Playgroud) javascript asp.net-mvc razor unobtrusive-validation asp.net-mvc-3