Asp.net-Mvc
從區域返回部分視圖失敗
基本上我剛剛在我的 ASP.NET MVC4 應用程序中創建了一個區域。這一切都很好,但是當我想返回一個 PartialView 時,如下所示:
return PartialView("_ImportSessionsTable", viewModel);(不是從區域(管理員)視圖呼叫上述呼叫)我收到以下錯誤:
未找到部分視圖“_ImportSessionsTable”或沒有視圖引擎支持搜尋的位置。搜尋了以下位置:~/Views/ImportSessions/_ImportSessionsTable.aspx
~/Views/ImportSessions/_ImportSessionsTable.ascx
~/Views/Shared/_ImportSessionsTable.aspx
~/Views/Shared/_ImportSessionsTable.ascx
~/Views/ImportSessions/_ImportSessionsTable.cshtml
~/Views/ImportSessions/_ImportSessionsTable.vbhtml
~/Views/Shared/_ImportSessionsTable.cshtml
~/Views/Shared/_ImportSessionsTable.vbhtml
問題是:據我所見,它不是在我儲存視圖的區域文件夾(管理員)中尋找視圖。我怎樣才能讓它在那裡看?每當我呼叫
return View();它時,它都可以正常工作,所以只有當我將視圖指定為字元串時。
我怎樣才能讓它在那裡看?
您可以指定要呈現的部分的完整位置:
return PartialView("~/Areas/Admin/Views/ImportSessions/_ImportSessionsTable.cshtml", viewModel);
您還可以考慮覆蓋視圖引擎搜尋視圖的位置,但這對於您要查找的內容可能有點極端。看這裡:連結