从 Blazor 中的异步功能禁用按钮

Disabling button from async function in Blazor

我的页面上有以下 EditForm 模型:

<EditForm Model="@projectParameters" OnValidSubmit="@SubmitProject">
       <MatButton Raised="true" Type="submit" Disabled="@saveButtonDisabled">@saveButtonName</MatButton>
</EditForm>

然后函数如下:

private async Task SubmitProject()
    {
        DisableSave();

        if (pageType == "Create")
        {
            await CreateProject();
        }
        else if (pageType == "Create")
        {
           await EditProject();
        }
    }

void DisableSave()
    {
        saveButtonDisabled = true;
        saveButtonName = "Saving...";
        StateHasChanged();
    }

SubmitProject 和 DisableSave 被正确调用,但 saveButtonName 和 disabled 在 CreateProject 工作时从未实际显示为已完成。我错过了什么?

刷新更改 await Task.Delay(1);:

private async Task SubmitProject()
{
    await DisableSave();
    ...

然后

async Task DisableSave()
{
    saveButtonDisabled = true;
    saveButtonName = "Saving...";
    await Task.Delay(1); //flush changes
    StateHasChanged(); // not needed
}