cshtml中的这一行
<partial name="_CookieConsentPartial" />
假设要在\Pages\Shared
文件夹中搜索_CookieConsentPartial.cshtml。
我可以在\Pages
文件夹中配置Web应用程序“以搜索_CookieConsentPartial”吗?
我已经删除了Shared文件夹,并将_CookieConsentPartial.cshtml移到\ Pages文件夹,但是在此<partial name="_CookieConsentPartial" />
停止工作后,<partial name="\_CookieConsentPartial.cshtml" />
开始工作了-但这是我要避免的事情。
答案 0 :(得分:1)
要配置其他搜索文件夹路径,您可以像这样配置RazorViewEngineOptions
:
services.Configure<RazorViewEngineOptions>(options => {
options.PageViewLocationFormats.Add("/Pages/Shared-1/{0}.cshtml");
});
默认情况下,PageViewLocationFormats已经定义/Pages/{0}.cshtml
// Remarks:
// Locations are format strings (see https://msdn.microsoft.com/en-us/library/txafckwd.aspx)
// which may contain the following format items:
// {0} - View Name {1} - Page Name
// Microsoft.AspNetCore.Mvc.Razor.RazorViewEngineOptions.PageViewLocationFormats
// work in tandem with a view location expander to perform hierarchical path lookups.
// For instance, given a Page like /Account/Manage/Index using /Pages as the root,
// the view engine will search for views in the following locations: /Pages/Account/Manage/{0}.cshtml
// /Pages/Account/{0}.cshtml /Pages/{0}.cshtml /Pages/Shared/{0}.cshtml /Views/Shared/{0}.cshtml
public IList<string> PageViewLocationFormats { get; }