<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 键时,我正在尝试运行一个函数,但到目前为止,我观察到的行为是其中的第一个button
元素,然后EditForm
在按 Enter 时被触发。有解决办法吗?