MVC Foolproof Validation using PassOnNull - Nullable or “01.01.0001 00:00:00”

三世轮回 提交于 2019-12-01 13:10:53

问题


I try tovalidate two dates (start -> end) where only the first ist required, but when the user enters the second date it must be greater than the first. I'm using the MVC Foolproof package with the "PassOnNull" parameter.

Model

<Required()> _
<DisplayName("Event Start")> _
<DataType(DataType.DateTime)> _
'This doesn't work:
Public Property EventStart As Nullable(Of DateTime)
'This does work but with the ugly default value in the textbox
Public Property EventStart As DateTime

<DisplayName("Event End")> _
<DataType(DataType.DateTime)> _
<GreaterThan("EventStart", PassOnNull:=True)> _
Public Property EventEnd As Nullable(Of DateTime)

I can get it to work with setting the EventStart date not NOT nullable but then i get a default date in the textbox with the value "01.01.0001 00:00:00" which is'nt even my country setting!

So I would like to get it to work with the nullable model propery or get rid of the "01.01.0001 00:00:00" value and have a blank textboy instead!


回答1:


Ok after reading http://foolproof.codeplex.com/discussions/220498 on Codeplex I now know it works the other way round:

<Required()> _
<DisplayName("Event Start")> _
<LessThan("EventEnd", PassOnNull:=True)> _
Public Property EventStart As Nullable(Of DateTime)

<DisplayName("Event End")> _
Public Property EventEnd As Nullable(Of DateTime)


来源:https://stackoverflow.com/questions/12406297/mvc-foolproof-validation-using-passonnull-nullable-or-01-01-0001-000000

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!