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

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!

Answers:

Thank you for visiting the Q&A section on Magenaut. Please note that all the answers may not help you solve the issue immediately. So please treat them as advisements. If you found the post helpful (or not), leave a comment & I’ll get back to you as soon as possible.

Method 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)


All methods was sourced from stackoverflow.com or stackexchange.com, is licensed under cc by-sa 2.5, cc by-sa 3.0 and cc by-sa 4.0

0 0 votes
Article Rating
Subscribe
Notify of
guest

0 Comments
Oldest
Newest Most Voted
Inline Feedbacks
View all comments
0
Would love your thoughts, please comment.x
()
x