输入类型文件在流利验证中需要验证
input type file required validation in fluent Validation
考虑以下代码片段
<input type='file' required />
现在,我不想使用上面的必需标记,而是想对文件使用流畅的验证 select。
请指导我
更新我的问题:
public class UploaderValidator : AbstractValidator<FileUploadViewModel>
{
public UploaderValidator()
{
RuleForEach(x => x.Files).SetValidator(x => new FileValidator());
}
}
在文件验证器中:
public class FileValidator : AbstractValidator<IFormFile>
{
public FileValidator()
{
RuleFor(x=>x.Length).NotNull().LessThanOrEqualTo(100)
}
}
例如,考虑上面的代码。
只有当文件从客户端 selected 并发送到服务器时,认证才会开始。
但我的目标是在文件未 selected 时发送消息。
事实上,文件 selection 必须是强制性的,这是通过流畅的验证完成的
RuleFor(x>=x.fileupkoad.files).NotNull.WithMessage("")
.DependentRules(()=>{
Validator ...
}
考虑以下代码片段
<input type='file' required />
现在,我不想使用上面的必需标记,而是想对文件使用流畅的验证 select。 请指导我
更新我的问题:
public class UploaderValidator : AbstractValidator<FileUploadViewModel>
{
public UploaderValidator()
{
RuleForEach(x => x.Files).SetValidator(x => new FileValidator());
}
}
在文件验证器中:
public class FileValidator : AbstractValidator<IFormFile>
{
public FileValidator()
{
RuleFor(x=>x.Length).NotNull().LessThanOrEqualTo(100)
}
}
例如,考虑上面的代码。 只有当文件从客户端 selected 并发送到服务器时,认证才会开始。 但我的目标是在文件未 selected 时发送消息。 事实上,文件 selection 必须是强制性的,这是通过流畅的验证完成的
RuleFor(x>=x.fileupkoad.files).NotNull.WithMessage("")
.DependentRules(()=>{
Validator ...
}