2015-09-29 126 views
0

我想提交一个表单,并且出现此错误。它似乎源于我的布局文件,因为我在布局中呈现了两个不同的局部视图用于多种目的。例如:不允许子操作执行重定向操作错误

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

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

子操作不允许执行重定向操作。 描述:执行当前Web请求期间发生未处理的异常。 请查看堆栈跟踪以获取有关 错误以及源代码的详细信息。

异常详细信息:System.InvalidOperationException: 不允许子操作执行重定向操作。

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

编辑: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"); 

     } 
+1

显示你的方法(这个消息是自我解释的 - 你试图用'[ChildActionOnly]'装饰的方法重定向' –

+0

我在这种情况下添加了Method for _MenuSearch。 –

+1

@StephenMuecke不一定装饰 - 它可以是在调用'RedirectToAction'的时候查看调用堆栈应该可以解释这个问题 –

回答

1

“办法”对孩子的行为寻找时没有考虑到 - 所以,当你处理POST请求,并在您查看调用Html.RenderAction("_MenuSearch", "Platform");public ActionResult _MenuSearch(LayoutViewModel viewModel)将有所回升,因为它被标记与HttpPost

通常可以安全地使用标记为ChildAction属性的特殊单独操作来避免此类情况。

+0

嗨Alexei。我添加了属性,但是我确实需要发布到该方法才能获得多个结果。那么它会告诉我它只能通过ChildActions –

+0

@LordRelix访问 - “*用ChildAction属性标记的单独操作*”。 –

相关问题