0
votes

I have a razor page that I developed based off of this Add Search tutorial by Microsoft.

Inside of the form on the page I have a Filter button which calls the OnGetAsync() method query string params and is working great. However, I added a reset button to the form as well. The reset button clears the form fields as expected, but without using JavaScript/jQuery how can I make another call that will end up with no query string params so the user's search is reset?

I was researching using handlers. Is this what I would use? Or can I have the reset button call the OnGetAsync as well, but with no query string params?

1

1 Answers

1
votes

For Razor Page query, it passes the parameters by query string like below:

http://localhost:64454/Movies?MovieGenre=Comedy&SearchString=

For clearing the query string, you could try:

<form>
    <p>
        <select asp-for="MovieGenre" asp-items="Model.Genres">
            <option value="">All</option>
        </select>
        Title: <input type="text" asp-for="SearchString" />
        <input type="submit" value="Filter" />
        <a asp-route-MovieGenre="" asp-route-SearchString="" class="btn btn-primary">ReSet</a>
    </p>
</form>