代码之家  ›  专栏  ›  技术社区  ›  Patricia

nhibernate.validator&x.Val&jQuery与自定义验证器

  •  0
  • Patricia  · 技术社区  · 16 年前

    我的验证器正在服务器端使用,但它没有连接到客户端的字段。

    正在验证的属性:

    
     _
        Public Property Password() As String
            Get
                Return m_Password
            End Get
            Set(ByVal value As String)
                m_Password = value
            End Set
        End Property
    
    

    
    Imports NHibernate.Validator.Engine
    Imports xVal.RuleProviders
    Imports xVal.Rules
    
    
     _
     _
    Public Class PasswordValidationAttribute
        Inherits Attribute
        Implements IRuleArgs
    
    
        Private m_Message As String = "Password and Confirm Password must be the same"
    
    
        Public Property Message() As String Implements NHibernate.Validator.Engine.IRuleArgs.Message
            Get
                Return m_Message
            End Get
            Set(ByVal value As String)
                m_Message = value
            End Set
        End Property
    End Class
    
    Public Class PasswordValidator
        Implements IValidator, ICustomRule
    
    
        Public Function IsValid(ByVal value As Object) As Boolean Implements NHibernate.Validator.Engine.IValidator.IsValid
            Dim valid As Boolean = True
            Dim val As String = CType(value, String)
    
            If val = "hello" Then
                valid = True
            Else
                valid = False
            End If
            Return valid
        End Function
    
        Public Function ToCustomRule() As xVal.Rules.CustomRule Implements xVal.RuleProviders.ICustomRule.ToCustomRule
            Return New CustomRule("ValidatePassword", Nothing, "Password and Password Confirmation must Match")
        End Function
    End Class
    
    

    这是html.ClientSideValidation(用户)在源代码中生成的内容的重要部分

    
    {"FieldName":"Password","FieldRules":[{"RuleName":"Required","RuleParameters":{},"Message":"Password is Required"}]},
    
    

    它附加了必需的字段验证器,但不是自定义的。

    有人能帮我吗?这是一个非常关键的功能!

    非常感谢。

    2 回复  |  直到 13 年前
        1
  •  0
  •   user187028 user187028    16 年前

    xVal.ActiveRuleProviders.Providers.Clear() 或者,如果您这样做了,请确保像这样添加CustomRulesProvider xVal.ActiveRuleProviders.Providers.Add(new xVal.RuleProviders.CustomRulesProvider())

        2
  •  0
  •   Patricia    16 年前

    推荐文章