MVC 3错误 - 儿童的行为是不允许执行重定向操作 [英] MVC 3 Error - Child actions are not allowed to perform redirect actions

查看:610
本文介绍了MVC 3错误 - 儿童的行为是不允许执行重定向操作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有这样的错误:

 执行的处理程序System.Web.Mvc.HttpHandlerUtil + ServerExecuteHttpHandlerAsyncWrapper'子请求错误。

内的例外是:

 儿童的行为是不允许进行重定向操作。

任何想法,为什么出现这种情况?

顺便说一下,错误发生在这条线:

  @ Html.Action(菜单,导航)

在导航控制器的菜单操作是这样的:

 公众的ActionResult菜单()
        {
           返回PartialView();
        }


解决方案

这是不允许的,因为MVC已经开始呈现视图浏览器(客户端)。
所以MVC框架块这一点,因为客户端已接收数据(HTML)。只要渲染过程中,你不能在你的子视图重定向。

您可以返回 RedirectToAction 代替。

I have this error:

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

The inner exception is:

Child actions are not allowed to perform redirect actions.

Any idea why this happening?

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();
        }

解决方案

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.

You can return RedirectToAction instead.

这篇关于MVC 3错误 - 儿童的行为是不允许执行重定向操作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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