[英]Child actions are not allowed to perform redirect actions error
我正在嘗試提交表格,但出現此錯誤。 它似乎源自我的布局文件,因為我在布局內部出於兩個目的渲染了兩個不同的局部視圖。 例:
@{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");
}
搜索子操作時會考慮“方法”-因此,當您處理POST請求並在視圖中調用Html.RenderAction("_MenuSearch", "Platform");
會選擇public ActionResult _MenuSearch(LayoutViewModel viewModel)
因為它已標記為HttpPost
。
通常,使用帶有ChildAction
屬性標記的特殊的單獨操作集來避免這種情況是安全的。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.