2012-06-12 103 views
3

我已經在我的代碼FluentValidation:驗證類型名稱必須是唯一

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

你能證明你的模型類? –

+0

是的 - 現在發佈 –

回答

4

確保您沒有 d使用任何數據註釋屬性來創建您的視圖模型類屬性。

正確:

[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; } 
} 
+0

我用我的模型代碼更新了我的帖子。正如你所看到的,我沒有任何地方的requried屬性。 –

+0

什麼是AuctionMetadata類?它似乎包含有關拍賣類的元數據。另外'AuctionStatus','Invitation'和'Lot'類又如何呢?它們是否包含數據註釋?它們是否裝飾了可能會添加數據註釋的元數據類? –

+0

是的,這是所需的屬性是 - 固定 - 標記爲答案:-) –

相關問題