ASP.NET MVC equivalent of Response.Redirect Click Event

I have an html form in a view that needs to be reset from time to time. The problem is that fields are allowed / disabled based on input. So the only way to really reset the form is to reload the view (I'd rather have the entire page reload). Due to several scenarios, the update just doesn't work. I need an equivalent to Response.Redirect () and redirect the view to itself ... Couldn't find a good solution yet.

I tried:

-Adding an ActionResult in the controller which

    public ActionResult ResetNoteReport()
    {
        return RedirectToAction("NoteReport");
    }

      

-Setting a click event on the button itself, which

onclick="window.location.href('<%= Url.Action("NoteReport")%>');"

      

-Remove input and set values ​​with null or "" via jQuery ...

Among many other bumps ... Any help would be greatly appreciated! Thanks!

+1


a source to share


4 answers


Sorry to waste my time on this. For some reason, my attempts at using window.location.href () were previously wrong and did not reload the page. When I came back to it, I tried to suggest your suggestion, but went back to window.location.href (). End result, I don't know what went wrong with it, but the following works great:

<script type="text/javascript">
    function reload() {
        window.location.href = "<%=Url.Action("NoteReport") %>";
    };
</script>

<%= Html.Button("reset", "Reset", HtmlButtonType.Button, "reload()") %> 

      



Thanks again for the quick responses! I love this site!

+2


a source


just as an aside, but instead of changing the page, can't you use one of the jquery form utilities to clear the form?



0


a source


The problem is that fields are allowed / denied based on input.

This is just one situation where MVC doesn't work. In such scenarios, WebForms perform much better.

0


a source


<%= Html.Button("reset", "Reset", HtmlButtonType.Button, "window.location.reload()") %>

      

0


a source







All Articles