C# Blazor EditForm带有自定义fluent验证器,更新时删除规则

C# Blazor EditForm带有自定义fluent验证器,更新时删除规则,c#,asp.net-core,blazor,fluentvalidation,blazor-server-side,C#,Asp.net Core,Blazor,Fluentvalidation,Blazor Server Side,我有自定义验证器 RuleFor(d => d.Id).NotEmpty() .Matches("^[0-9]*$") .WithMessage("Id must consist of number!") .MustAsync(async (id, token) => { // make http request if (s

我有自定义验证器

RuleFor(d => d.Id).NotEmpty()
            .Matches("^[0-9]*$")
            .WithMessage("Id must consist of number!")
            .MustAsync(async (id, token) =>
            {
                // make http request

                if (someCase)
                {
                    return false;
                }

                return true;
            }).WithMessage("Some error");
并在EditForm中使用它作为

<FluentValidationValidator ValidatorType=typeof(MyValidator) />

到目前为止,它还可以工作,但在更新(使用相同的Razor组件)时,Id字段被禁用,如果我更改了验证器的其他值部分,它也会检查Id并返回IsValidfalse(因为它已经存在)。如何修复此问题?

向验证器添加状态应该可以工作

private bool\u有效;
(d=>d.Id).NotEmpty()的规则
.匹配(“^[0-9]*$”)
.WithMessage(“Id必须由数字组成!”)
.MustAsync(异步(id,令牌)=>
{
如果(_有效)
{
返回true;
}
//发出http请求
如果(某个案例)
{
返回false;
}
_isValid=true;
返回true;
}).WithMessage(“某些错误”);
EditContext = new EditContext(MyModel);
EditContext.OnFieldChanged += async (sender, e) =>
{
   IsInvalidForm = !(await Validator.ValidateAsync(MyModel)).IsValid;
   StateHasChanged();
};