2

我的页面上有以下 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 被正确调用,但是当 CreateProject 工作时 saveButtonName & disabled 从未真正显示为已完成。我错过了什么?

4

1 回答 1

6

刷新更改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
}
于 2019-09-19T19:02:37.863 回答