나는 성 검증을 사용하고 있는데 내 유효성 검사기가 작동하지 않는 이유를 알고 싶습니다클라이언트 측 캐슬 검증을위한 맞춤형 검사기를 작성하는 방법은 무엇입니까?
[Serializable]
public class PositiveIntegerValidator : AbstractValidator
{
public override bool IsValid(object instance, object fieldValue)
{
if (fieldValue == null || !(fieldValue is int))
return false;
return ((int)fieldValue) > 0;
}
public override bool SupportsBrowserValidation
{
get { return true; }
}
public override void ApplyBrowserValidation(BrowserValidationConfiguration config, InputElementType inputType, IBrowserValidationGenerator generator, System.Collections.IDictionary attributes, string target)
{
base.ApplyBrowserValidation(config, inputType, generator, attributes, target);
generator.SetValueRange(target, 0,int.MaxValue, ErrorMessage);
}
protected override string BuildErrorMessage()
{
return ErrorMessage;
}
}
public class ValidatePositiveIntegerAttribute : AbstractValidationAttribute
{
public ValidatePositiveIntegerAttribute(string msg) :base(msg){}
public override IValidator Build()
{
PositiveIntegerValidator positiveIntegerValidator = new PositiveIntegerValidator();
ConfigureValidatorMessage(positiveIntegerValidator);
return positiveIntegerValidator;
}
}
을 그리고 내 필드
public class PackageViewModel
{
// ...
[ValidateNonEmpty,ValidatePositiveInteger("The package count must be positive")]
public int nbPackage { get; set; }
//...
}
그리고 내보기
$FormHelper.TextField("package.nbPackage","%{size='3',value='1'}")
ValidateNonEmpty는 클라이언트 측과 서버 측에서 유효성을 검사하지만 ValidatePositiveInteger는 유효하지 않습니다.
이 스레드를 보았습니다. Min Length Custom AbstractValidationAttribute and Implementing Castle.Components.Validator.IValidator,하지만 내 코드와 그의 차이점을 볼 수는 없습니다.