相关疑难解决方法(0)

剃刀引擎无法找到视图

我试图在不使用Web请求的情况下从视图中呈现html.我需要HTML作为字符串,在内部,我不希望提供它.

viewEngine.FindView()返回一个viewEnineResult,显示未找到任何视图.它显示搜索它看起来像这样的位置:

/Views//PDFOperationsReportView.cshtml

/Views/Shared/PDFOperationsReportView.cshtml

(观察第一行中的双正斜杠)

文件结构(我将其放入HTML片段,因为我无法在此编辑器中正确设置文本格式)

Project 
  Folder 
    Subfolder
        CodeFile.cs
  Views
    PDFOperationsReportView.cshtml
Run Code Online (Sandbox Code Playgroud)

代码:

   var viewName = "PDFOperationsReportView";
        var actionContext = GetActionContext();
        var viewEngineResult = _viewEngine.FindView(actionContext, viewName, false);
        if (!viewEngineResult.Success)
        {
            throw new InvalidOperationException(string.Format("Couldn't find view '{0}'", viewName));
        }

        var view = viewEngineResult.View;
Run Code Online (Sandbox Code Playgroud)

razor razorengine asp.net-core-mvc

6
推荐指数
1
解决办法
4310
查看次数

IRazorViewEngine.FindView 与 GetView 找不到视图

在我的 asp.net core 项目中,我尝试使用以下方法查找 Razor 视图:

private IView FindView(ActionContext actionContext, string viewName)
{
    var getViewResult = _viewEngine.GetView(executingFilePath: null, viewPath: viewName, isMainPage: true);
    if (getViewResult.Success)
    {
        return getViewResult.View;
    }

    var findViewResult = _viewEngine.FindView(actionContext, viewName, isMainPage: true);
    if (findViewResult.Success)
    {
        return findViewResult.View;
    }

    var searchedLocations = getViewResult.SearchedLocations.Concat(findViewResult.SearchedLocations);
    var errorMessage = string.Join(
        Environment.NewLine,
        new[] { $"Unable to find view '{viewName}'. The following locations were searched:" }.Concat(searchedLocations));

    throw new InvalidOperationException(errorMessage);
}
Run Code Online (Sandbox Code Playgroud)

在哪里

viewName = "Views/Email/ResetPassword.cshtml"
Run Code Online (Sandbox Code Playgroud)

_viewEngineIRazorViewEngine但没有找到任何。

我的项目结构:

项目结构

IView.FindView方法是从 Business …

razorengine asp.net-core-mvc asp.net-core

5
推荐指数
1
解决办法
4302
查看次数