简体   繁体   中英

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. 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.

I need to have these partial views inside my layout, yet I cannot submit other forms. What can I do?

EDIT: MenuSearch Method:

    [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"); than public ActionResult _MenuSearch(LayoutViewModel viewModel) will be picked since it is marked with HttpPost .

It is generally safe to have special separate set of actions marked with ChildAction attribute to avoid such cases.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM