Issue—Blazor ValueChanged event did not fire with built-in input elements.
This code will help you to understand how to do if Issue—Blazor ValueChanged event did not fire with built-in input elements
<EditForm Model="person">
<DataAnnotationsValidator />
<div class="form-group">
<label for="name">Name</label>
<InputText ValueChanged="@ValueChange" Value="@person.FirstName" ValueExpressions= "@( () => @person.FirstName )" Class="form-control" Id="name" />
</div>
</EditForm>
@code {
Person person = new Person();
public void ValueChange()
{
Console.WriteLine(person.FirstName);
}
}
Instead, you can also use the OnValidSubmit form event to get and process the value.
<EditForm Model="person" OnValidSubmit="@ValueChange">
<DataAnnotationsValidator />
<div class="form-group">
<label for="name">Name</label>
<InputText @bind-Value="@person.FirstName" Class="form-control" Id="name" />
</div>
</EditForm>
@code {
Person person = new Person();
public void ValueChange()
{
Console.WriteLine(person.FirstName);
}
}