简体   繁体   English

回发后的MVC3 RedirectToAction

[英]MVC3 RedirectToAction after postback

With MVC, I hear that it's good practice to get back to a 'GET' action by using RedirectToAction after processing the Http postback. 使用MVC,我听说在处理Http回发后使用RedirectToAction返回到“ GET”操作是一种好习惯。 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. 我认为这很明智,但是重定向后模型错误丢失了,所以我无法使用Html.ValidationSummary显示它们。 What is the recommended practice in this scenario? 在这种情况下,推荐的做法是什么? Many thanks 非常感谢

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. 实际上,所有逻辑都发生在重定向之前-插入新数据,检查数据,显示错误,更正数据,保存数据,重定向,插入新数据。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM