为什么重定向结果没有儿童行动允许Asp.net MVC 2 [英] Why are Redirect Results not allowed in Child Actions in Asp.net MVC 2

查看:119
本文介绍了为什么重定向结果没有儿童行动允许Asp.net MVC 2的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有我的Asp.Net期货法的RenderAction呈现一些局部的行动。有些执行重定向在其中的形式已经被处理了。

I have some partial actions that I render with the Asp.Net Futures RenderAction method. Some of these perform redirects after the forms in them have been processed.

现在我升级到Asp.Net MVC 2 RC它给了我一个错误孩子的行为是不允许执行重定向操作。

Now that I upgraded to Asp.Net MVC 2 RC it gives me an error "Child actions are not allowed to perform redirect actions".

我检查了源$ C ​​$ c和我发现,抛出异常的线。为了解决它,我可以做一个自定义的RedirectResult,但我做之前,我想知道为什么架构不允许它摆在首位。必须有一个很好的理由,也许我不应该做任何

I checked out the source code and I found the line that throws the exception. To Get around it I can make a custom RedirectResult, But before I do I want to understand why the framework doesn't allow it in the first place. There must be a good reason and maybe I Shouldn't do either.

任何一个知道这个限制的原因是什么?

Any one know the reason for this limitation?

感谢

推荐答案

的限制,是因为MVC已经开始渲染视图给客户端。从这个角度重定向的效果是不明确的。它可以很好地工作,它可能继续呈现原始视图没有重定向,它可以抛出一个不同的异常等。

The limitation exists because MVC has already started rendering a view to the client. The effect of redirecting from this point is undefined. It could work perfectly, it could continue rendering the original view without redirecting, it could throw a different exception, etc.

由于在执行此操作的结果是不确定的,框架块吧。在实践中,应该的RenderAction永远不会被用来渲染以外的其他视图出于同样的原因任何东西(或视图类的内容)。

Since the result of performing this action is undefined, the framework blocks it. In practice, RenderAction should never be used to render anything other than a view (or view-like content) for similar reasons.

在特定的情况下,外部动作应该重定向。如果你只是去年底从视图中重定向反正不显示给用户任何东西,那么就真的没有目的,通过在首位的观点去,因为外部行动可能已采取适当下放的工作的自己的。

In your particular case, the outer action should redirect. If you're just going to end up redirecting from within the view anyway without showing anything to the user, then there was really no purpose to going through the view in the first place, as the outer action could have delegated the work appropriately on its own.

这篇关于为什么重定向结果没有儿童行动允许Asp.net MVC 2的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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