dotnet / aspnetcore

ASP.NET Core is a cross-platform .NET framework for building modern cloud-based web applications on Windows, Mac, or Linux.
https://asp.net
MIT License
35.19k stars 9.93k forks source link

Blazor 3.0 official release asyc function with parameter? #14753

Closed gxomin closed 4 years ago

gxomin commented 4 years ago

I am trying to create a async function in Blazor WebAssembly project, in preview 8, this worked:

  <th @onclick="@(async ()=> await Sort(column.Name))">@column.Name</th>

@code {
    async Task Sort(string column)
    {
        await Http.PostJsonAsync<SelectResult>("Data/Get");
        this.StateHasChanged();
    }
}

With 3.0 final release, it does not work anymore. Compiler complains: Cannot convert lambda expression to type 'object' because it is not a delegate type ...\Pages\Table.razor

Can you please suggest how to do async event with parameters? Thanks very much.

mkArtakMSFT commented 4 years ago

Thanks for contacting us, @gxomin. You should be able to resolve this by adding @using Microsoft.AspNetCore.Components.Web to your .razor file (or _Imports.razor, which is the preferred place for this particular namespace).

mythrz commented 4 years ago

mouse right click "quick actions" could be added in these type of errors? had the same problem, solved. ty