ASP.NET MVC 控制器返回不在共享文件夹中的部分视图
我的控制器中有一个调用此部分视图的方法:
return PartialView("_tinzProdListPageTemplate", tblStoreLocation);
该部分视图位于 Shared 文件夹内,上面的代码工作正常并加载视图。但现在我想将 _tinzProdListPageTemplate
移动到 Shared
文件夹内名为 Templates
的另一个文件夹,以便我可以更好地组织我的项目。
我尝试过这些,但它们不起作用。似乎只有直接从默认的 Shared 文件夹调用时,才能从控制器加载部分视图。 (我什至尝试将 .cshtml
添加到末尾作为上面示例的扩展,但也不起作用)
return PartialView("Templates/_tinzProdListPageTemplate", tblStoreLocation);
return PartialView("Shared/Templates/_tinzProdListPageTemplate", tblStoreLocation);
return PartialView("~/Shared/Templates/_tinzProdListPageTemplate", tblStoreLocation);
那么如何返回不在 PartialView
内的 PartialView
代码>共享文件夹。它位于 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
I have this method inside my controller that calls this partial view:
return PartialView("_tinzProdListPageTemplate", tblStoreLocation);
That partial view is inside the Shared
folder and the above code works fine and loads the view. But now I want to move _tinzProdListPageTemplate
to another folder that is inside the Shared
folder called Templates
so that I can better organize my project.
I tried these but they don't work. It seems that only when calling straight from the default Shared
folder, can you load a partial view from the controller. (I even tried adding .cshtml
to the end as the extension on the examples above but did not work either)
return PartialView("Templates/_tinzProdListPageTemplate", tblStoreLocation);
return PartialView("Shared/Templates/_tinzProdListPageTemplate", tblStoreLocation);
return PartialView("~/Shared/Templates/_tinzProdListPageTemplate", tblStoreLocation);
So how do I return a PartialView
that is not inside the Shared
folder. Its inside a folder that is inside the Shared
folder?
I am using ASP.NET MVC 5 running on the .NET Framework.
This is the error I get:
The partial view '_tinzProdListPageTemplate' was not found or no view engine supports the searched locations. The following locations were searched:
~/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
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
完整的视图名称如下所示
我认为您只是忘记在末尾添加扩展名。
也许你想要一个像这里一样的 CustomViewEngine
在自定义视图引擎中使用子文件夹
如果您注册了自定义视图引擎,那么您可以设置所有搜索位置,例如
A complete view name would look like this
I think you only forgot to add the extension at the end.
Maybe you want a CustomViewEngine like here
Working with subfolders in custom view engine
If you register a custom view engine then you can set all the search locations like