简体   繁体   English

子操作不允许执行重定向操作错误

[英]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.

相关问题 错误:子操作不允许执行重定向操作 - Error: Child actions are not allowed to perform redirect actions 子操作不允许执行重定向操作 - Child actions are not allowed to perform redirect actions “不允许子操作执行重定向操作” - “Child actions are not allowed to perform redirect actions” 子操作不允许执行重定向操作。 (使用PartialViews) - Child actions are not allowed to perform redirect actions. (Using PartialViews) 子操作不允许执行重定向操作MVC4 - Child actions are not allowed to perform redirect actions MVC4 ASP.NET MVC 3 + Razor错误:不允许子操作执行重定向操作 - ASP.NET MVC 3 + Razor Error: Child actions are not allowed to perform redirect actions 在部分视图控制器中无法正常工作。(错误 - 不允许子操作执行重定向操作。) - doesn't work redirecttoaction in partial view controller.(Error - Child actions are not allowed to perform redirect actions.) 不允许子操作执行重定向操作 - 使用ASP.NET MVC 2和Razor时出错 - Child actions are not allowed to perform redirect actions - error while working with ASP.NET MVC 2 and Razor 如何解决不允许子操作执行重定向操作,其他答案不解决 - How to fix Child actions are not allowed to perform redirect actions, other answers does not fix 重定向到区域操作中的操作 - Redirect to action in area actions
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM