Question

I have an html form in a view that needs to be reset from time to time. Problem is, fields enable/disable based on input. Therefore, the only way to truly reset the form is to reload the view (I would prefer that the entire page is reloaded). Due to several scenarios, simply refreshing does not work. I need the equivalent to Response.Redirect() and have the view redirect to itself... Haven't been able to find a good solution yet.

I have tried:

-Adding an ActionResult in the controller that

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

-Setting a click event on the button itself that

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

-Removing input and setting values to null or "" via JQuery...

Among plenty of other stabs... Any help would be greatly apreciated! Thanks!

Was it helpful?

Solution

Sorry to waste your time with this. For some reason, my attempts at using window.location.href() was buggy earlier and would not reload the page. When I got back to it, I attempted your suggestion, but ended up back to the window.location.href(). End result, I don't know what was wrong with it before, but the following works perfectly fine:

<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!

OTHER TIPS

just an aside but rather than change the page could you not use one of the jquery form utilities to clear the form?

Problem is, fields enable/disable based on input.

That is exactly one situation when MVC is not good to go with. WebForms perform much better in such scenarios.

<%= Html.Button("reset", "Reset", HtmlButtonType.Button, "window.location.reload()") %>
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top