Blazor: How to use onkeyup with parameter and KeyboardEventArgs

Wenn the user set the focus to a link and presses a key, I need to register it, proof the key and get the a parameter from the link.

I know to read the key without a parameter and I know to transfer a parameter. But I can’t figure out how to do both.

How can I get a parameter (document) and the KeyboardEventArgs (or key) from the link?

@foreach (var document in DocumentList)
{
    <a tabindex="0" type="button" @onclick="() => ShowDocument(document)" 
    @onkeyup="OnDocumentKeyUp(document)">@document.Doname</a>
}

@code{
    private void OnDocumentKeyUp(Do document, KeyboardEventArgs e) // THIS IS MY WISH, BUT NOT WORKING
    {
        if (e.Code is "Enter" or "NumpadEnter" or " " or "Space")
        {
            ShowDocument(document);
        }
    }
}

>Solution :

Like this: @onkeyup="e => OnDocumentKeyUp(document, e)"

Leave a Reply