我可以从 Child 操作方法重定向到新操作方法和 return 他们的视图而不是 return 重定向到那个 child 的 parent 吗?

Can I Redirect from Child Action Method to the New Action Method and return their view instead of returning to the parent of that child?

假设我有一个动作方法,例如伪代码

Pseudo Code is here 这是否可以从 child 重定向到另一个 parent 操作方法和 return 他们的视图而不是 returning 视图到那个 [=21= 的 parent ] ?

您可以 return 从任何操作中得到您喜欢的任何响应。使用您的示例:

public ActionResult Method()
{
    return ChildActionMethod();
}

public ActionResult ChildActionMethod()
{
    return RedirectToAction("SomeAction");
}

这将 return 来自 Method 的重定向结果,因为它 returning 任何 ChildActionMethod returns.

值得注意的是,如果您在ChildActionMethod内执行return View();并且没有指定视图,框架将使用当前请求来确定使用哪个视图。也就是说,默认情况下它将使用 Method 而不是 ChildActionMethod 的视图。在这种情况下,您需要指定视图。

事实上,ChildActionMethod甚至不需要是public"action method"。它可以是 return 和 ActionResult 的任何方法。此时,您处理的只是 C# 语言的基础知识(方法、类型等),而不是 ASP.NET MVC 框架。