【问题标题】:MVC Foolproof Validation using PassOnNull - Nullable or "01.01.0001 00:00:00"使用 PassOnNull 进行 MVC 万无一失的验证 - 可空或“01.01.0001 00:00:00”
【发布时间】: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


    【解决方案1】:

    好的,在 Codeplex 上阅读 http://foolproof.codeplex.com/discussions/220498 后,我现在知道它可以反过来工作:

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2013-04-05
      • 1970-01-01
      • 1970-01-01
      • 2010-11-24
      • 1970-01-01
      • 2011-08-30
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多