Я хочу найти свой cshtml
файл в моем проекте ASP.NET Core 2.1 Web API. Для этого я использую этот код:
var httpContext = new DefaultHttpContext { RequestServices = this.serviceProvider };
var actionContext = new ActionContext(httpContext, new RouteData(), new ActionDescriptor());
var viewResult = this.razorViewEngine.FindView(
actionContext,
"~/PdfTemplate/ProjectRaport.cshtml",
false);
Файл находится здесь:

Но из приведенного выше кода View
(то есть ~/PdfTemplate/ProjectRaport.cshtml
) равно нулю.
Как найти определенный файл по пути в WebApi Core
?
Этот код работает нормально:
var viewResult = this.razorViewEngine.FindView(actionContext,
Path.Combine(this.hostingEnvironment.ContentRootPath, "PdfTemplate", "ProjectRaport.cshtml"),
false);
Путь к файлу в порядке, но View
в viewResult
по-прежнему нулевой
Когда я пытался GetView
:
var viewResult = this.razorViewEngine.GetView(
Path.Combine(this.hostingEnvironment.ContentRootPath, "PdfTemplate", "ProjectRaport.cshtml"),
Path.Combine(this.hostingEnvironment.ContentRootPath, "PdfTemplate", "ProjectRaport.cshtml"),
false);
viewResult.View
все еще нулевой
EDIT
В SearchedLocations
путь в порядке:


Когда я удалил .cshtml
расширение, SearchedLocations
пусто