简体   繁体   中英

Blazor The name 'Invoke' doesn exist in the current context

I am using Visual Studio 2019 Preview 4, .NET Core 3 RC1,

I create a Blazor web-app (server blazor), I follow https://docs.devexpress.com/Blazor/DevExpress.Blazor.Base.DxTextBoxBase.TextChanged#remarks

<DxTextBox Text="" TextChanged=@((newValue) => OnTextChanged(newValue))></DxTextBox>
<button type="button" class="btn btn-primary" disabled=@IsDisabled>Update Text</button>

@code {
    bool IsDisabled = true;

    void OnTextChanged(string newValue)
    {
        if (newValue != null)
            IsDisabled = false;

        Invoke(StateHasChanged);
    }
}

I catch error

The name 'Invoke' doesn exist in the current context

在此处输入图像描述

How to fix it?

You now need to call InvokeAsync() in its place.

This was changed in the Preview 8 release, mentioned here . Check the breaking changes at the top of that blog post, as well as those in the Preview 9 post , as you may encounter other errors from updating. There were no breaking changes from Preview 9 to RC1, and will likely be no further changes for the 3.0 release in 11 hours.

You change it to

<DxTextBox Text="" TextChanged=@((newValue) => OnTextChanged(newValue))></DxTextBox>
<button type="button" class="btn btn-primary" disabled=@IsDisabled>Update Text</button>

@code {
    bool IsDisabled = true;

    void OnTextChanged(string newValue)
    {
        if (newValue != null)
            IsDisabled = false;

        InvokeAsync(StateHasChanged);
    }
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM