Reset submit button not working using MVC 2

I have two buttons inside a form call:

<% using (Html.BeginForm()) {%>

    <input type="submit" value="Filter" />
    <input type="reset" value="Clear Filter" />

Fields in question:

        <td>
            <%:Html.TextBox("filterId", Model.IdFilter, new {style="width:100px"}) %>
        </td>
        <td>
            <%:Html.TextBox("filterTitle", Model.TitleFilter, new {style="width:500px"}) %>
        </td>
        <td>
            <%:Html.TextBox("filterStatus", Model.StatusFilter, new {style="width:100px"}) %>
        </td>

The first button invokes the action of the form. The second button should:

  • Clear form and do not post messages
  • Redirect to another action

Not sure why I have so many problems with this, but it seems like there should be a very simple way to do this. However, all the solutions I came across seem too complicated for this.

Am I missing something?

EDIT: here's the solution:

Change the reset button to a simple jane button with identifier:

<input type="button" value="Clear Filter" id="clearFilter" />

Then add this script:

    $(function () {
        $("#clearFilter").click(function () {
            $(':input', '#form0')
                .not(':button, :submit, :reset, :hidden')
                .val('');
            $('#form0').submit();
        });
    })
+3
source share
1 answer

, script, . reset, , .

, , "", , , .

0

Source: https://habr.com/ru/post/1768161/


All Articles