2012-01-25 17 views
0

我有2列在UI中輸入。如何根據ASP.NET MVC3中的錯誤消息和條件的這兩列給出正則表達式?將jQuery驗證轉換爲ASP.NET MVC驗證

的條件是jQuery中,我遷移到MVC3方:

if (((new Date(Date.parse($("#hupUnempBftsEndDate").val()) - Date.parse($("#hupUnempBftsBeginDate").val())))/86400000) < 0) { 
    validationSummary = validationSummary + "! End Date of Unemployment Benefits can't be prior to Effective Date of Unemployment Benefits. \n"; 

.NET代碼:

public DateTime? BeginDate { get; set; } 
public DateTime? EndDate { get; set; } 

回答

2

你可以看看MVC Foolproof Validation提供額外的屬性或乾脆寫您自己的自定義屬性:

[Required] 
public DateTime? BeginDate { get; set; } 

[Required] 
[GreaterThan("BeginDate")] 
public DateTime? EndDate { get; set; } 

另一種可能性是使用FluentValidation.NET其中integrates與ASP.NET MVC非常好。

+0

感謝達林....我寫了一個自定義的驗證。! – user1169594

0

,如果您有興趣使用DataAnnotations jQuery的服務器和客戶端驗證和編寫自己的檢驗,我寫了一個blog article about this