本文介绍了在 ASP.NET MVC 视图中呈现 HTML 文件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
在我看来,想将 HTML 文件的内容呈现为局部视图.但是当我将它添加到 .cshtml 视图时,它给了我这个错误:
In my view, would like to render the contents of an HTML file as a partial view. It is giving me this error though when I add this to the .cshtml view:
@Html.Partial(Url.Content("~/Test/main.html"))错误:
Exception Details: System.InvalidOperationException: The partial view '/Scripts/main.html' was not found or no view engine supports the searched locations. The following locations were searched: /Scripts/main.html虽然文件在物理上.有什么不同的方式我应该这样做吗?
The file is physically there though. Is there a different way I should be doing this?
推荐答案您不能为此使用 Html.Partial.它是一种特殊的渲染 Partial Views 的辅助方法.相反,您可以像这样添加 Action:
You can't use Html.Partial for this.It is a special helper method for rendering Partial Views. Instead you can add an Action like this:
[ChildActionOnly] public ActionResult GetHtmlPage(string path) { return new FilePathResult(path, "text/html"); }您可以使用 View 调用它.aspx" rel="noreferrer">Html.Action 辅助方法:
And you can call it from your View with using Html.Action helper Method:
@Html.Action("GetHtmlPage","controllername", new { path = "~/Test/main.html" })更多推荐
在 ASP.NET MVC 视图中呈现 HTML 文件?
发布评论