2015-09-29 125 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屬性標記的單獨操作*」。 –

相關問題