I just spent ages trying to get Blazor not to submit and reload the page but fire off my methods instead on enter key. With
<form><input type="text" class="form-text" @bind-value:event="oninput" @onkeydown="Enter" @bind-value="@searchString" /><button type="button" class="btn btn-primary" @onclick="Search">Search</button></form>Whenever I hit enter the page would get reloaded if I used the enter key instead of click, preventing the results from showing. So I added
<button type="submit" disabled hidden></button>Which fixed it.
Now this to me looks like a workaround. Is there a more elegant way to do this? If I had the original button as submit it wouldnt work either. I think this works because there is a submit button for the enter key to hit, but being disabled it cant do anything.