ASP.NET MVC等效于Response.Redirect单击事件

时间:2022-11-23 13:06:11

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.

我在视图中有一个html表单,需要不时重置。问题是,字段根据输入启用/禁用。因此,真正重置表单的唯一方法是重新加载视图(我希望重新加载整个页面)。由于几种情况,只是刷新不起作用。我需要等效于Response.Redirect()并让视图重定向到自己......还没有找到一个好的解决方案。

I have tried:

我试过了:

-Adding an ActionResult in the controller that

- 在控制器中添加ActionResult

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

- 通过JQuery删除输入和设置值为null或“”...

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

在众多其他刺中...任何帮助都会大大贬低!谢谢!

4 个解决方案

#1


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:

抱歉浪费你的时间。出于某种原因,我尝试使用window.location.href()之前是错误的,不会重新加载页面。当我回到它时,我尝试了你的建议,但最终回到了window.location.href()。最终结果,我不知道它之前有什么问题,但以下工作完全正常:

<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


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

只是暂时而不是更改页面,你可以不使用其中一个jquery表单实用程序来清除表单?

#3


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.

这正是MVC不适合的一种情况。 WebForms在这种情况下表现更好。

#4


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

#1


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:

抱歉浪费你的时间。出于某种原因,我尝试使用window.location.href()之前是错误的,不会重新加载页面。当我回到它时,我尝试了你的建议,但最终回到了window.location.href()。最终结果,我不知道它之前有什么问题,但以下工作完全正常:

<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


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

只是暂时而不是更改页面,你可以不使用其中一个jquery表单实用程序来清除表单?

#3


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.

这正是MVC不适合的一种情况。 WebForms在这种情况下表现更好。

#4


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