剃刀引擎找不到视图

编程入门 行业动态 更新时间:2024-10-25 02:24:12
本文介绍了剃刀引擎找不到视图的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

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

Im trying to render a html from a view without using a web request. I need the HTML as a string, internally, i do not wish to serve it.

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

The viewEngine.FindView() returns a viewEnineResult that shows no view was found. It shows to search locations where it looked they look like this:

/Views//PDFOperationsReportView.cshtml

/Views//PDFOperationsReportView.cshtml

/Views/Shared/PDFOperationsReportView.cshtml

/Views/Shared/PDFOperationsReportView.cshtml

(请注意第一行中的双正斜杠)

(Observe the double forward slash in the first line)

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

File structure (I placed it into a HTML snippet cause i couldnt manage to format the text properly in this editor)

Project Folder Subfolder CodeFile.cs Views PDFOperationsReportView.cshtml

代码:

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;

推荐答案

我遇到了同样的问题.我在这里找到了答案: GitHub aspnet/Mvc问题#4936

I had the same issue. I found the answer here: GitHub aspnet/Mvc Issue #4936

基本上,使用GetView代替FindView,如下所示:

Basically, use GetView instead of FindView, like this:

var viewResult = razorViewEngine.GetView(viewName, viewName, false);

更多推荐

剃刀引擎找不到视图

本文发布于:2023-11-16 12:59:45,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1604500.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:剃刀   找不到   视图   引擎

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!