2016-08-10 21 views
0

我真的堅持這一點。Html.Action引發「異步操作」InvalidOperationException

我的ActionResult是如下

public ActionResult HolidayReport() 
{ 
    return View("~/Views/Employee/GetEmployeeHolidayReport.cshtml"); 
} 

目前擁有的

<div class="panel panel-default panel-main"> 
    <div class="panel-body"> 
     @{ Html.RenderAction("Test"); }   
    </div> 
</div> 

視圖內容完成的緣故,這是Test行動

public ActionResult Test() 
{ 
    return new EmptyResult(); 
} 

甚至沒有去控制器或其他任何類型的東西都會拋出異常

An asynchronous operation cannot be started at this time. Asynchronous operations may only be started within an asynchronous handler or module or during certain events in the Page lifecycle. If this exception occurred while executing a Page, ensure that the Page is marked <%@ Page Async="true" %>. This exception may also indicate an attempt to call an "async void" method, which is generally unsupported within ASP.NET request processing. Instead, the asynchronous method should return a Task, and the caller should await it. 

關於@{ Html.RenderAction("Test"); }部分在視圖中。 交換@ Html.Action()導致同樣的問題。可能會發生什麼?

+0

發佈您的「測試」操作。 – mxmissile

+0

它甚至沒有進入控制器,我已經嘗試了不同的操作。異步任務和常規ActionResult – Perry

回答

0

Test操作大概是異步的(返回Task<T>)。 Asynchronous child actions are not supported on ASP.NET MVC 4。請注意,ASP.NET Core支持的異步視圖組件

如果您尚未準備好遷移到ASP.NET Core,那麼您最好的選擇是使Test同步。

+0

測試只是一種我最終在挫折中創建的方法,它是一個普通的ActionResult。但它甚至沒有進入控制器,它在視圖中拋出一個異常並將異常拋入錯誤處理程序 – Perry