我的控制器中有這個方法,它呼叫這個區域視圖:
return PartialView("_tinzProdListPageTemplate", tblStoreLocation);
該部分視圖位于Shared檔案夾內,上面的代碼可以正常作業并加載視圖。但現在我想移動到名為的檔案夾_tinzProdListPageTemplate內的另一個檔案夾,以便更好地組織我的專案。SharedTemplates
我試過這些,但它們不起作用。似乎只有直接從默認Shared檔案夾呼叫時,才能從控制器加載區域視圖。(我什至嘗試.cshtml在上面的示例中添加到末尾作為擴展名,但也沒有用)
return PartialView("Templates/_tinzProdListPageTemplate", tblStoreLocation);
return PartialView("Shared/Templates/_tinzProdListPageTemplate", tblStoreLocation);
return PartialView("~/Shared/Templates/_tinzProdListPageTemplate", tblStoreLocation);
那么我如何回傳一個PartialView不在檔案夾內的Shared檔案。它在檔案夾內的Shared檔案夾內?
我正在使用在 .NET Framework 上運行的 ASP.NET MVC 5。
這是我得到的錯誤:
未找到部分視圖“_tinzProdListPageTemplate”或沒有視圖引擎支持搜索的位置。搜索了以下位置:
~/Views/Store/_tinzProdListPageTemplate.aspx
~/Views/Store/_tinzProdListPageTemplate.ascx
~/Views/Shared/_tinzProdListPageTemplate.aspx
~/Views/Shared/_tinzProdListPageTemplate.ascx
~/Views/Store/_tinzProdListPageTemplate.cshtml
~/Views/Store /_tinzProdListPageTemplate.vbhtml
~/Views/Shared/_tinzProdListPageTemplate.cshtml
~/Views/Shared/_tinzProdListPageTemplate.vbhtml
uj5u.com熱心網友回復:
完整的視圖名稱如下所示
“~/Areas/Public/Views/Home/Index.cshtml”
我認為您只是忘記在最后添加擴展名。
也許你想要一個像這里這樣的 CustomViewEngine
在自定義視圖引擎中使用子檔案夾
如果您注冊了自定義視圖引擎,那么您可以設定所有搜索位置,例如
ViewLocation, PartialViewLocation, MasterLocation
轉載請註明出處,本文鏈接:https://www.uj5u.com/gongcheng/435306.html
標籤:C# asp.net-mvc 控制器 asp.net-mvc-partialview
上一篇:.NetCore=我想為UserValidator添加個性規則
下一篇:抗鋸齒圓在opencv中呈鋸齒狀
