To read the current value of an input using @onkeypress event, this event uses the KeyboardEventArgs. You can also get the last pressed key value in args.Key.
[index.razor]
@page"/"
<input type="text" @onkeypress="@Keypress" />
<h1>@KeyPressed</h1>
@code {
string KeyPressed = "";
private void Keypress(KeyboardEventArgs args)
{
KeyPressed = "Key Pressed is " + args.Key;
}
}
Share with