问题描述
MudBlazor 表单可以在 Blazor 中使用 Fluent 验证进行验证。我遵循了文档中的相同代码:
- 创建通用FluentValueValidator类
public FluentValueValidator(Action<IRuleBuilderInitial<T,T>> rule)
{
rule(RuleFor(x => x));
}
- 创建该类的对象(例如dependencyLinkValidator)
public FluentValueValidator<string> dependencyLinkValidator = new FluentValueValidator<string>(x => x
.NotEmpty().WithMessage("{PropertyName} cannot be empty.").WithName("Link"));
- 将 Validator 属性的值放入 dependencyLinkValidator
Validation="dependencyLinkValidator.Validation"
Form.Validate();
该示例很简单,即使使用自定义验证器也能完美运行,但问题是,当我创建使用异步函数的自定义验证器时,验证不起作用。有没有办法异步调用Form.Validate()?
自定义异步验证器示例:
public FluentValueValidator<string> dependencyLinkValidator = new FluentValueValidator<string>(x => x
.NotEmpty().WithMessage("{PropertyName} cannot be empty.")
.MustAsync(async (x,cancellation) =>
{
return await AsyncFunction(x);
}).WithMessage("Site doesn't exist")
.WithName("Link"));
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)