2015-03-02 113 views
0

我需要驗證2個日期:「開始日期」和「結束日期」。 「開始日期」必須從今天到未來,「結束日期」必須等於或大於「開始日期」。我怎樣才能用數據註解來做到這一點?可能嗎?ASP.NET MVC 4使用DataAnnotation進行數據驗證

+0

你看過自定義驗證屬性嗎? – 2015-03-02 11:31:47

+0

看看這個http://www.dotnetglobe.com/2012_01_01_archive.html – 2015-03-02 11:32:49

+0

http://stackoverflow.com/questions/10887824/greater-than-or-equal-to-today-date-validation-annotation- in-mvc3,http://stackoverflow.com/questions/18577777/mvc-validation-lower-higher-than-other-value,http://stackoverflow.com/questions/19882296/mvc4-data-annotation-compare-兩個日期,http://stackoverflow.com/questions/7025198/mvc-custom-validation-compare-two-dates – CodeCaster 2015-03-02 11:34:28

回答

2

您可以在波紋管鏈接提到與DataAnnotations做到這一點:

  1. Greater Than or Equal To Today Date validation annotation in MVC3
  2. MVC Validation Lower/Higher than other value
  3. mvc4 data annotation compare two dates
  4. MVC custom validation: compare two dates

,作爲建議,SOLV e這通過Javascript庫更容易比DataAnnotation s更像Jquery Input Mask

+1

客戶端驗證(如Jquery輸入掩碼)很好,但始終檢查服務器端..(http://stackoverflow.com/ a/15855799/130420) – Guillaume 2015-12-20 08:27:38