我正在使用ASP.NET Core 5 Razor页面。可以使用通用模板Pages/Shared
,但是我需要将其重命名为Pages/Foo
。
如何指示运行时在其中查找文件Pages/Foo
?
我认为这是可能的Startup.ConfigureServices()
:
services.AddRazorPages(options => {
options.Conventions.??? // what goes here?
});
用于定位Razor页面视图的路径在中定义PageViewLocationFormats
,这是的属性RazorViewEngineOptions
。您可以操纵此集合来自定义这些路径。
这是一个例子:
services.AddRazorPages()
.AddRazorOptions(o =>
{
var indexOfPagesShared = o.PageViewLocationFormats.IndexOf("/Pages/Shared/{0}.cshtml");
o.PageViewLocationFormats.RemoveAt(indexOfPagesShared);
o.PageViewLocationFormats.Insert(indexOfPagesShared, "/Pages/Foo/{0}.cshtml");
});
修改列表有很多不同的方法,但是此示例显示了如何用替换现有/Pages/Shared
路径/Pages/Foo
。它对root(/Pages
)和文件扩展名进行了假设,但这是典型的。
请注意,如果您使用区域,则还有一个AreaPageViewLocationFormats
属性。
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句