C# Blazor: How to prevent specific key on input like in JS with e.preventDefault()?

Unfortunately there is no easy solution for this at the moment. For that scenario you would still need to use a JS event handler and probably some interop if you want to call back into your .NET code.

You will find a very brief comment from Steve Sanderson about the reason (async handlers) here https://github.com/dotnet/aspnetcore/issues/14517#issuecomment-559184498

Another workaround is to bind your input to a variable and update the values manually. (also pointed out here PreventDefault on Blazor input ) But this is probably a bumpy road.

Personally, I would love to see the preventDefault and stopPropagation as part of the EventArgs that are passed into the C# method handlers. I assume that this is technically challenging. However, it would simplify a lot of use cases. You might want to open a issue for this over at aspnetcore.

Tags:

C#

Blazor