RedirectToAction、Redirect、Return View的区别

return RedirectToAction()

RedirectToAction是从一个Action调到另一个Action,在后台做跳转。

重定向到某个控制器的页面,可以传递参数。

比如:return RedirectToAction(“view","controller" , new {param1=value1,param2=value2 });

这样传递的参数,参数放在ViewData里面,前台获取参数的方式为:

<input id="taskType" name="taskType" type="hidden" value='@ViewData["param1"]' />

或者

<input id="taskType" name="taskType" type="hidden" value='@Request.Params["param1"]' />

 

return View() 

服务器端产生数据,让一个View去显示的,即Return View是让服务器把指定的cshtml的内容运行渲染后给到浏览器

可使用ViewData和ViewBag两种形式,只不过在前台获取参数的方式不同而已。

若使用ViewBag的方式传递:

则:后台:ViewBag.param1= value1;

前台:<input id="taskType" name="taskType" type="hidden" value='@ViewBag.param1' />

Response.Redirect()方法:

Response.Redirect是给返回前台返回应答,前台根据应答的url进行跳转;让浏览器去访问另外一个页面
https://www.cnblogs.com/wfy680/p/15413396.html

 

Server.Trasfer

原文地址:https://www.cnblogs.com/wfy680/p/15413392.html