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

本文关键字:操作 错误 重定向 不允许 执行 | 更新日期: 2023-09-27 18:14:53

我正在尝试提交一个表单,我得到这个错误。它似乎源于我的布局文件,因为我有两个不同的部分视图内呈现的布局为几个目的。例子:

 @{Html.RenderAction("_MenuSearch", "Platform");}

这是在我的布局中,平台控制器用它接收和管理某些数据。我可以毫无问题地发帖。当我用另一个模型提交表单时,主要问题就出现了。我得到这个:

子操作不允许执行重定向操作。描述:在执行当前web请求期间发生了未处理的异常。有关的更多信息,请查看堆栈跟踪错误和它在代码中的起源。

Exception Details: System。InvalidOperationException:子操作不允许执行重定向操作。

我需要在我的布局中有这些局部视图,但我不能提交其他表单。我能做什么?

编辑:菜单搜索方法:

    [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" -因此当您处理POST请求时,在您的视图中调用Html.RenderAction("_MenuSearch", "Platform");而不是public ActionResult _MenuSearch(LayoutViewModel viewModel)将被选中,因为它被标记为HttpPost

一般来说,使用ChildAction属性标记特殊的单独的操作集是安全的,以避免这种情况。