Skip to content

Event binding guidance improvements#36611

Open
guardrex wants to merge 2 commits intomainfrom
guardrex/blazor-binding
Open

Event binding guidance improvements#36611
guardrex wants to merge 2 commits intomainfrom
guardrex/blazor-binding

Conversation

@guardrex
Copy link
Collaborator

@guardrex guardrex commented Jan 12, 2026

Fixes #35976

@danroth27 @javiercn ... Holding until we figure out the right guidance to provide.

I probably need a code example of the "mapping" part of the suggestion. The direction that I thought you were pitching is (and I'll use onkeyup as my example because onkeydown is probably best served by just oninput) ...

using Microsoft.AspNetCore.Components;

namespace {APP NAMESPACE};

[EventHandler("onkeyup", typeof(ChangeEventArgs),
    enableStopPropagation: true, enablePreventDefault: true)]
public static class EventHandlers
{
}

... but that with ...

<input @bind="boundValue" @bind:event="onkeyup" />

... throws an unhandled exception. Perhaps, it's because onkeyup is already mapped as a keyboard event argument.

One simple approach for this scenario is to use @on delegate event handler syntax ...

<input @onkeyup="@((KeyboardEventArgs args) => boundValue = args.Key)" />

... but that's not the ask on the issue, and it's clunky compared to @bind:event="onkeyup" syntax (if that can be made to work).


Internal previews

📄 File 🔗 Preview link
aspnetcore/blazor/components/data-binding.md aspnetcore/blazor/components/data-binding
aspnetcore/blazor/components/event-handling.md aspnetcore/blazor/components/event-handling

@guardrex guardrex marked this pull request as ready for review January 13, 2026 11:40
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Additional information regarding restrictions of events that can be used with @bind:event is needed

1 participant