2017-03-01 54 views
0

我爲我的MVC 5應用程序使用MVC Foolproof Validation多MVC萬無一失驗證

我想說:EventPlanEnd是,除非EventPlanStart填充需要如果是,請確保EventPlanEnd> EventPlanStart。這似乎並沒有工作...

public Nullable<System.DateTime> EventPlanStart { get; set; } 

[RequiredIfTrue("EventPlanStart")] 
[GreaterThan("EventPlanStart")] 
public Nullable<System.DateTime> EventPlanEnd { get; set; } 

任何想法我可以做到這一點與數據註釋?

+0

[MVC防呆驗證使用PassOnNull - 可空或 「01.01.0001 00:00:00」]的可能的複製(http://stackoverflow.com/questions/12406297/mvc- foolproof-validation-using-passonnull-nullable-or-01-01-0001-000000) – CodeCaster

+0

''[RequiredIfTrue]'只適用於其他屬性爲'bool'的情況 –

回答

0

也許你可以使用RequiredIfNot而不是RequiredIfTrue這需要boolean。這是一個未測試的代碼:

public Nullable<System.DateTime> EventPlanStart { get; set; } 

[RequiredIfNot("EventPlanStart", null)] 
[GreaterThan("EventPlanStart")] 
public Nullable<System.DateTime> EventPlanEnd { get; set; }