In .NET 7, you can run asynchronous logic after a binding event has completed using the new @bind:after
modifier. In the following example, the PerformSearch
asynchronous method runs automatically after any changes to the search text are detected:
<input @bind="searchText" @bind:after="PerformSearch" /> @code { private string searchText; private async Task PerformSearch() { ... } }
In .NET 7, it’s also easier to set up binding for component parameters. Components can support two-way data binding by defining a pair of parameters:
@bind:get
: Specifies the value to bind.@bind:set
: Specifies a callback for when the value changes.
The @bind:get
and @bind:set
modifiers are always used together.
Example:
<input @bind:get="Value" @bind:set="ValueChanged" /> @code { [Parameter] public TValue? Value { get; set; } [Parameter] public EventCallback<TValue> ValueChanged { get; set; } }