回发后的 MVC3 RedirectToAction
对于 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 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
在显示错误之前,您不应允许重定向。事实上,所有逻辑都发生在重定向之前——插入新数据、检查数据、显示错误、更正数据、保存数据、重定向、插入新数据。
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.