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

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

问题描述

我有此错误:

执行处理程序'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天全站免登陆