Car*_*lis 2 asp.net-mvc razor asp.net-core
我正在开发一个用于 ASP.NET Core MVC 的库。对于这个库,我需要获取应用程序中存在的所有(已编译的)Razor 视图(路径和内容)的列表。
有没有办法在运行时查找应用程序中所有已编译的 Razor 视图?到目前为止,我还没有找到答案。
无法迭代 .cshtml 文件,因为使用编译视图时它们不会被发布。
为了获得合规的视图路径,您可以尝试ViewsFeature像
public class HomeController : Controller
{
private readonly IViewCompilerProvider _viewCompilerProvider;
private readonly ApplicationPartManager _applicationPartManager;
public HomeController(IViewCompilerProvider viewCompilerProvider
, ApplicationPartManager applicationPartManager)
{
_viewCompilerProvider = viewCompilerProvider;
_applicationPartManager = applicationPartManager;
}
public IActionResult Index()
{
var feature = new ViewsFeature();
_applicationPartManager.PopulateFeature(feature);
var views = feature.ViewDescriptors;
return View();
}
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
911 次 |
| 最近记录: |