【问题标题】:MVC Redirect ActionResultMVC 重定向操作结果
【发布时间】:2012-07-24 21:58:47
【问题描述】:

在 MVC 控制器上,我有以下内容:

public virtual ActionResult Test() {
  ActionResult result = MVC.Home.Index();
  return RedirectToAction(result);
  return View();
}

这会重定向到结果。视图永远不会返回。

现在我需要做如下事情:

public virtual ActionResult Test() {
  ActionResult result = MVC.Home.Index();
  MyClass.RedirectTo(result, this);
  return View();
}

其中 MyClass.RedirectTo 方法如下:

public static void RedirectTo(ActionResult result, Controller controller) {
  controller.Response.Redirect(result.ToString());            
}

但在这种情况下,重定向不会发生。

返回视图。有谁知道怎么做?

【问题讨论】:

  • 我有 3 个问题:1)为什么在控制器中使用虚拟方法? 2)以天堂的名义,您如何在 1 种方法中编写 2 个返回语句? 3)你能用纯文本解释你真正想要实现的目标吗?
  • 你想把你的用户带到哪里?
  • 你好。我确实在我的控制器中使用虚拟。但是在尝试了这个之后,我认为我想做的事情是不可能的。我正在尝试另一种方法......基本上在我的控制器上,我得到了 DTO 响应。响应包含 DTO 模型和异常信息。基本上我正在尝试为那些会在错误时触发 RedirectToAction 的响应创建一个流畅的验证......但我现在明白我要走的路是不可能的。

标签: asp.net-mvc actionresult


【解决方案1】:

您好,您必须重定向到特定控制器上的特定操作

例如 return RedirectToAction("Index", "ControllerName");

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2020-05-17
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多