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 に答える