Blazor cannot execute OnChange Event
See original GitHub issueHello, I have an issue with the InputSelect tag, I want to execute OnChange handler and pass additional parameters into it, but situation is that, the OnChange method is successfully completed but the selected value of the target drop-down was deselected. I upload my code. The problem is hit on the first InputSelect
ValueChanged="@((UserRoleType value) => this.GetUsersInOutOfRole(value, false))"
@page "/AdministrationPanel"
@attribute [Authorize(Roles = GlobalConstants.AdministratorRole)]
@inject IAdministrationService administrationService
<PageTitle>Administration Panel</PageTitle>
<h3 class="pageHeading">Administration Panel</h3>
<hr />
<div class="row">
<div class="col-12 col-sm-12">
<h4 class="sectionHeading">Add User In Role</h4>
</div>
</div>
<EditForm Model="@this.model" OnValidSubmit="@(async () => await this.AddUserInRole())">
<DataAnnotationsValidator />
<ValidationSummary />
<div class="form-group">
<div class="row">
<div class="col-5 col-sm-5">
<label>Role Type</label>
<InputSelect
class="form-control"
ValueExpression="@(() => this.model.RoleType)"
Value="@this.model.RoleType"
ValueChanged="@((UserRoleType value) => this.GetUsersInOutOfRole(value, false))">
<option value="" selected disabled>Select role...</option>
@foreach (var roleType in ((UserRoleType[])Enum.GetValues(typeof(UserRoleType))).OrderBy(x => x.ToString()))
{
<option value="@roleType">@(roleType.ToString().SplitCamelCase())</option>
}
</InputSelect>
<ValidationMessage For="@(() => this.model.RoleType)" />
</div>
<div class="col-5 col-sm-5">
<label>Username</label>
<InputSelect class="form-control" @bind-Value="this.model.UserName">
<option value="" selected disabled>Select user...</option>
@foreach (string username in this.usernames.OrderBy(x => x.ToString()))
{
<option value="@username">@(username)</option>
}
</InputSelect>
<ValidationMessage For="@(() => this.model.UserName)" />
</div>
<div class="col-2 col-sm-2">
<button class="btn btn-primary" type="submit">Add</button>
</div>
</div>
</div>
</EditForm>
@code {
AddRemoveUserToFromRoleInputModel model = new AddRemoveUserToFromRoleInputModel();
List<string> usernames = new List<string>();
private async Task AddUserInRole()
{
}
private async Task GetUsersInOutOfRole(UserRoleType roleType, bool inRole)
{
this.usernames =await this.administrationService.GetUsernamesInOutOfRole(roleType, inRole);
this.StateHasChanged();
}
}
Regards, Simeon Valev
Issue Analytics
- State:
- Created 2 years ago
- Comments:7 (6 by maintainers)
Top Results From Across the Web
onChange event not firing Blazor InputSelect
The problem is the @bind attribute makes use of the @onchange event and Blazor will not allow multiple @onchange event handlers.
Read more >Executing async operations onchange in Blazor
When you use the @bind or @bind-Value directive, Blazor generates an onchange event handler behind the scenes which is used to update the...
Read more >Cannot bind value of element and have onchange event ...
If I can't have bind and have an onchange for a single dropdown then I need to figure out a way to call...
Read more >ASP.NET Core Blazor event handling
Delegate event handlers automatically trigger a UI render, so there's no need to manually call StateHasChanged . Exceptions are logged. The ...
Read more >Trying to use TelerikEditor OnChange="@SomeMethod"
While the OnChange event is not something that the Editor supports (in Blazor and in other suites), exposing an OnBlur event seems like...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
You aren’t updating the
this.model.RoleType
value inside theGetUsersInOutOfRole
function. This will result inthis.model.RoleType
never changing.and might be what’s causing your issue.
Thanks @MariovanZeist, marking resolved.