回发后的 MVC3 RedirectToAction

发布于 2024-12-03 19:15:30 字数 181 浏览 7 评论 0原文

对于 MVC,我听说在处理 Http 回发后使用 RedirectToAction 返回“GET”操作是一个很好的做法。据我了解,这样如果用户刷新页面或书签并重新访问它,则不会重复回发。 我认为这是明智的,但重定向后模型错误会丢失,因此我无法使用 Html.ValidationSummary 显示它们。 在这种情况下,推荐的做法是什么? 非常感谢

With MVC, I hear that it's good practice to get back to a 'GET' action by using RedirectToAction after processing the Http postback. I understand this is so the postback is not repeated should the user refresh the page or bookmark and revisit it.
I think that is sensible but after the redirect the model errors are lost so I can't display them using Html.ValidationSummary.
What is the recommended practice in this scenario?
Many thanks

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

眼前雾蒙蒙 2024-12-10 19:15:30

在显示错误之前,您不应允许重定向。事实上,所有逻辑都发生在重定向之前——插入新数据、检查数据、显示错误、更正数据、保存数据、重定向、插入新数据。

You shouldn't allow to redirect before errors are displayed. In fact, all logic happens before redirect - insert new data, check data, display errors, correct data, save data, redirect, insert new data.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文