我的代码中指定了以下规则
RuleFor(x => x.Auction_Round1Ring1Start).GreaterThan(DateTime.Now);
RuleFor(x => x.Auction_Round1Ring1End).GreaterThan(x => x.Auction_Round1Ring1Start);
RuleFor(x => x.Auction_Round1Ring2Start).GreaterThan(x => x.Auction_Round1Ring1End);
RuleFor(x => x.Auction_Round1Ring2End).GreaterThan(x => x.Auction_Round1Ring2Start);
RuleFor(x => x.Auction_Round1Ring3Start).GreaterThan(x => x.Auction_Round1Ring2End);
RuleFor(x => x.Auction_Round1Ring3End).GreaterThan(x => x.Auction_Round1Ring3Start);
RuleFor(x => x.Auction_Round2Start).GreaterThan(x => x.Auction_Round1Ring3End);
我收到此错误
Validation type names in unobtrusive client validation rules must be unique. The following validation type was seen more than once: required
我在视图中的这一行上收到此错误
@Html.EditorForModel()
答案 0 :(得分:4)
确保没有使用任何数据注释属性修饰视图模型类属性。
正确:
[Validator(typeof(MyViewModelValidator))]
public class MyViewModel
{
public DateTime Auction_Round1Ring1Start { get; set; }
public DateTime Auction_Round1Ring1End { get; set; }
public DateTime Auction_Round1Ring2Start { get; set; }
public DateTime Auction_Round1Ring2End { get; set; }
public DateTime Auction_Round1Ring3Start { get; set; }
public DateTime Auction_Round1Ring3End { get; set; }
public DateTime Auction_Round2Start { get; set; }
}
错:
[Validator(typeof(MyViewModelValidator))]
public class MyViewModel
{
[Required]
public DateTime Auction_Round1Ring1Start { get; set; }
public DateTime Auction_Round1Ring1End { get; set; }
public DateTime Auction_Round1Ring2Start { get; set; }
public DateTime Auction_Round1Ring2End { get; set; }
public DateTime Auction_Round1Ring3Start { get; set; }
public DateTime Auction_Round1Ring3End { get; set; }
public DateTime Auction_Round2Start { get; set; }
}