Skip to content

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
@guardrex
Copy link
Collaborator Author

guardrex commented Jan 20, 2026

@danroth27 @javiercn @oroztocil @ilonatommy ... I'm stuck on a technical problem here. Anyone free to assist?

We describe onchange and oninput for binding. A dev asked about other events, which aren't wired up OOB to work. Dan, you said map the event to make it work. I'm trying to get the following to bind (boundValue is a field) ...

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

Per the discussion on #35976, I thought that we'd just need ...

using Microsoft.AspNetCore.Components;

namespace {APP NAMESPACE};

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

It 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).

How can ...

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

... be made to work?

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

2 participants