具有Enter按钮的Blazor InputText触发功能

时间:2020-07-10 17:15:17

标签: blazor-webassembly

    <EditForm class="form-inline col-md-12 p-3" Model="searcher" OnValidSubmit="OnSearchSubmit">
    <input class="form-control w-100 mr-3"
           type="text"
           @bind-value="searcher.SearchText"
           @onkeypress="KeyHandler"
           placeholder="Enter employee name to filter" />
    <ValidationMessage For="()=> searcher.SearchText" />
    <div class="mx-auto mt-2">
        <button type="submit" class="btn btn-primary mr-3">Search</button>
        <button class="btn btn-primary " @onclick="ShowEmployeeList" @onclick:stopPropagation="true">Reset</button>
    </div>

</EditForm>

   //Function
    private async Task KeyHandler(KeyboardEventArgs e)
{
    if (e.Key == "Enter")
    {
        await OnSearchSubmit();

    }

}

我试图运行某个函数,当我在InputText框中按下Enter键时,但到目前为止,我观察到的行为是{{1}中的第一个button元素的行为}在按下Enter键时被解雇。有没有解决的办法?

0 个答案:

没有答案