Home > OS >  Compiler error when using the new @bind:after feature in Blazor .NET7
Compiler error when using the new @bind:after feature in Blazor .NET7

Time:11-15

Been looking at the new binding features introduced for Blazor in .NET7. This Microsoft article explains how to use @bind:after (see the paragraph starting "To execute asynchronous logic after binding...")

I copied the code almost verbatim, replacing the call to SearchService with a Console.WriteLine...

<input @bind="searchText" @bind:after="PerformSearch" />

@code {
  private string? searchText;

  private async Task PerformSearch() =>
    Console.WriteLine($"Search: {searchText}");
}

However, this gives a compiler error... "Argument 3: cannot convert from 'Microsoft.AspNetCore.Components.EventCallback' to 'System.Action<string?>'"

This is in a brand new Blazor server project targeting .NET7 in VS Community 2022.

Anyone any idea why I'm getting this error, and how I use this new feature?

CodePudding user response:

It's a known issue that should get fixed soon.

See this github issue for details.

  • Related