当你使用View()与RedirectToAction [英] When do you use View() vs. RedirectToAction

查看:171
本文介绍了当你使用View()与RedirectToAction的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这<一个href=\"http://stackoverflow.com/questions/5521158/difference-between-redirecttoaction-and-view\">existing问题总结了我的问题的基础知识。的最佳答案有告诉这两种方法之间的差异。我要寻找指引,用哪种方法。

This existing question sums up the basics of my question. The best answers there tells the difference between the two methods. I am looking for guidelines as to which method to use.

在短,我在该方法的格式,并然后显示处理的结果的控制器的动作。什么时候应该使用返回查看(),而不是返回RedirectToAction(FormResult)

In short, I have an action in a controller which process a form and then display the results of the processing. When should I use return View() as opposed to return RedirectToAction("FormResult")?

推荐答案

您可以真正使用两种。一般来说,虽然形式发布后,你想,这样刷新页面不会导致形式重新发布重定向。但是,有时它不是状态复制到新的页面可行的,你的处理幂这样刷新就不会伤害任何东西。

You can really use either. Generally speaking, though, after a form is posted you want to redirect so that refreshing the page doesn't cause the form to repost. Sometimes, however, it's not feasible to copy state to the new page and your processing is idempotent so refresh wouldn't hurt anything.

这并不是说有一个坚硬和快速的规则。你有种必须权衡的利弊和得失。

It's not that there's a hard-and-fast rule. You kind of have to weigh the pros and the cons.

这篇关于当你使用View()与RedirectToAction的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆