redirectToAction()和视图之间的差异() [英] Difference between redirectToAction() and View()

查看:209
本文介绍了redirectToAction()和视图之间的差异()的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

由于我在MVC新的任何机构可以告诉我是什么样的区别返回RedirectToAction()返回查看()

As i am new in mvc Can any body tell me what is the difference between return RedirectToAction() and return view()

推荐答案

返回查看()告诉MVC生成HTML要显示,并将其发送给浏览器。

return View() tells MVC to generate HTML to be displayed and sends it to the browser.

[RedirectToAction()] [1] 告诉ASP.NET MVC要通过浏览器响应重定向到一个不同的动作,而不是渲染HTML。该浏览器将收到通知重定向,使新动作另一个请求。

[RedirectToAction()][1] tells ASP.NET MVC to respond with a Browser redirect to a different action instead of rendering HTML. The browser will receive the redirect notification and make another request for the new action.

这是例子...

假设你正在建设一个形式,收集和保存数据,您的网址看起来像SomeEntity /编辑/ 23。在编辑动作,你会做返回查看()来渲染输入字段的表单来收集数据。

let's say you are building a form to collect and save data, your URL looks like SomeEntity/Edit/23. In the Edit action you will do return View() to render a form with input fields to collect the data.

在这个例子中,让我们说,在成功保存要显示已保存的数据的数据。处理后的用户提交的数据,如果你做的东西像 RedirectToAction(「指数」),其中指数是将显示数据的操作。该浏览器将得到一个HTTP 302(临时重定向)去/ SomeEntity /索引/ 23。

For this example let's say that on successful save of the data you want to display the data that has been saved. After processing the user's submitted data, if you do something like a RedirectToAction("Index") where Index is the action that will display the data. The browser will get a HTTP 302 (temporary redirect) to go to /SomeEntity/Index/23.

希望这有助于。

这篇关于redirectToAction()和视图之间的差异()的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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