“不允许子操作执行重定向操作" [英] "Child actions are not allowed to perform redirect actions"

查看:30
本文介绍了“不允许子操作执行重定向操作"的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有这个错误:

执行处理程序System.Web.Mvc.HttpHandlerUtil+ServerExecuteHttpHandlerAsyncWrapper"的子请求时出错.

Error executing child request for handler 'System.Web.Mvc.HttpHandlerUtil+ServerExecuteHttpHandlerAsyncWrapper'.

内部异常:

不允许子操作执行重定向操作.

Child actions are not allowed to perform redirect actions.

知道为什么会这样吗?

顺便说一句,错误发生在这一行:

Incidentally, the error is happening on this line:

@Html.Action("Menu", "Navigation")

导航控制器中的菜单操作如下所示:

The Menu Action in the Navigation Controller looks like this:

public ActionResult Menu()
{
    return PartialView();
}

推荐答案

这是不允许的,因为 MVC 已经开始将视图渲染到浏览器(客户端).所以 MVC 框架阻止了这一点,因为客户端已经接收到数据 (html).只要渲染正在进行中,您就无法在子视图中重定向.

This is not allowed because MVC has already started Rendering the View to the browser (client). So the MVC Frameworks blocks this, because the client already receives data (html). As long as the rendering is in progress you not able to redirect in your child view.

您可以改为返回 RedirectToAction.

这篇关于“不允许子操作执行重定向操作"的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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