3

我的代码中指定了以下规则

    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()
4

1 回答 1

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; }
}
于 2012-06-12T09:22:57.820 回答