例如
返回RedirectToAction(“SomeAction”,“SomeController”);
我需要将以前控制器的一些数据提供给我重定向到的新控制器。
答案 0 :(得分:1)
如果您没有传递对象或复杂的东西,请使用参数。只需确保重定向的操作获取参数以显示它应该显示的内容。
return RedirectToAction("SomeAction", "SomeController",new { id=someString} );
在操作中获取参数:
public ActionResult SomeAction(string id)
{
//do something with it
}
答案 1 :(得分:1)
@UfukHacıoğulları:您无法使用ViewData在2个控制器之间共享信息。 ViewData仅在Controller和View之间共享信息。
如果您需要在重定向时在多个控制器之间共享复杂信息,请改用“TempData”。
以下是使用“TempData”的方式 - http://msdn.microsoft.com/en-us/library/dd394711.aspx
答案 2 :(得分:0)
重定向将向客户端发送一个http响应,指示它再向/SomeController/SomeAction
发出新的http请求。另一种方法是直接在另一个控制器上调用方法......例如new SomeController().SomeAction(someData)
。
答案 3 :(得分:0)
我认为这有助于您将值从一个操作传递到另一个操作。
public ActionResult ActionName(string ToUserId)
{
ViewBag.ToUserId = ToUserId;
return View();
}
public ActionResult ssss(string ToUserId)
{
return RedirectToAction("ActionName", "ControllerName", new { id = @ToUserId });
}