我想将我的MVC项目分成几个项目
首先,我创建了两个项目Front和Views
该阵线项目是一个Web应用程序,其中包含控制器和模型
本次项目是一个类库项目,将只包含的意见
我的问题是如何在Views项目中创建控制器调用视图
我有像这样的控制器:
public ActionResult Default()
{
return this.View();
}
Run Code Online (Sandbox Code Playgroud) 我想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);
Run Code Online (Sandbox Code Playgroud)
该文件在这里:
但是从上面的代码来看,View(即~/PdfTemplate/ProjectRaport.cshtml)为空。
如何通过路径查找特定文件WebApi Core?
这段代码工作正常:
var viewResult = this.razorViewEngine.FindView(actionContext,
Path.Combine(this.hostingEnvironment.ContentRootPath, "PdfTemplate", "ProjectRaport.cshtml"),
false);
Run Code Online (Sandbox Code Playgroud)
文件的路径是确定的,但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);
Run Code Online (Sandbox Code Playgroud)
在viewResult.View仍然为空
编辑
在SearchedLocations路径中是可以的: …