【发布时间】:2012-09-13 12:29:43
【问题描述】:
我尝试验证仅需要第一个日期的两个日期(开始 -> 结束),但是当用户输入第二个日期时,它必须大于第一个。我正在使用带有“PassOnNull”参数的 MVC Foolproof 包。
型号
<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)
我可以通过设置 EventStart 日期而不是 NOT 为空,但随后我在文本框中得到一个默认日期,其值为“01.01.0001 00:00:00”,即'甚至我的国家设置!
所以我想让它与可为空的模型属性一起使用,或者摆脱“01.01.0001 00:00:00”值并改为使用空白文本男孩!
【问题讨论】:
标签: asp.net asp.net-mvc validation data-annotations