[英]Child actions are not allowed to perform redirect actions error
I am trying to submit a Form and I am getting this error. 我正在尝试提交表格,但出现此错误。 It seems to originate from my layout file as I have two different partial views rendered inside the layout for several purposes. 它似乎源自我的布局文件,因为我在布局内部出于两个目的渲染了两个不同的局部视图。 Example: 例:
@{Html.RenderAction("_MenuSearch", "Platform");}
This is inside my layout, and the Platform controller receives and manages certain data with this. 这是在我的布局内,并且平台控制器以此接收和管理某些数据。 I can post to it without issue. 我可以发布它没有问题。 The main problem happens when I submit a form with another Model. 当我使用其他模型提交表单时,会发生主要问题。 I get this: 我得到这个:
Child actions are not allowed to perform redirect actions. 子操作不允许执行重定向操作。 Description: An unhandled exception occurred during the execution of the current web request. 说明:执行当前Web请求期间发生未处理的异常。 Please review the stack trace for more information about the error and where it originated in the code. 请查看堆栈跟踪,以获取有关错误及其在代码中起源的更多信息。
Exception Details: System.InvalidOperationException: Child actions are not allowed to perform redirect actions. 异常详细信息:System.InvalidOperationException:不允许子操作执行重定向操作。
I need to have these partial views inside my layout, yet I cannot submit other forms. 我需要在布局中包含这些局部视图,但不能提交其他表单。 What can I do? 我能做什么?
EDIT: MenuSearch Method: 编辑:MenuSearch方法:
[HttpGet]
public PartialViewResult _MenuSearch()
{
LayoutViewModel viewModel = new LayoutViewModel();
return PartialView(viewModel);
}
[HttpPost]
public ActionResult _MenuSearch(LayoutViewModel viewModel)
{
Guid? memberKey = _memberInfoService.GetMemberId(viewModel.MemberIdentifier);
if (memberKey == null)
{
return RedirectToAction("NoResults", "Platform");
}
else
{
Session["MemberFound"] = true;
Session["MemberGuid"] = memberKey;
return RedirectToAction("MemberDisplay/" + memberKey.ToString(), "Platform");
}
"Method" is taken into account when searching for child actions - so when you handle POST request and in you view calling Html.RenderAction("_MenuSearch", "Platform");
搜索子操作时会考虑“方法”-因此,当您处理POST请求并在视图中调用Html.RenderAction("_MenuSearch", "Platform");
than public ActionResult _MenuSearch(LayoutViewModel viewModel)
will be picked since it is marked with HttpPost
. 会选择public ActionResult _MenuSearch(LayoutViewModel viewModel)
因为它已标记为HttpPost
。
It is generally safe to have special separate set of actions marked with ChildAction
attribute to avoid such cases. 通常,使用带有ChildAction
属性标记的特殊的单独操作集来避免这种情况是安全的。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.