I want to find my cshtml file in my ASP.NET Core 2.1 Web API project. To do it, I'm using this code:
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);
The file is here:
But from code above, the View (that is ~/PdfTemplate/ProjectRaport.cshtml) is null.
How to find specific file by path in WebApi Core?
This code works ok:
var viewResult = this.razorViewEngine.FindView(actionContext,
Path.Combine(this.hostingEnvironment.ContentRootPath, "PdfTemplate", "ProjectRaport.cshtml"),
false);
Path to file is ok, but the View in viewResult is still null
When I tried GetView:
var viewResult = this.razorViewEngine.GetView(
Path.Combine(this.hostingEnvironment.ContentRootPath, "PdfTemplate", "ProjectRaport.cshtml"),
Path.Combine(this.hostingEnvironment.ContentRootPath, "PdfTemplate", "ProjectRaport.cshtml"),
false);
the viewResult.View is still null
EDIT
In SearchedLocations the path is ok:
When I deleted .cshtml extension, SearchedLocations is empty





