在 ASP.NET MVC 视图中呈现 HTML 文件?

编程入门 行业动态 更新时间:2024-10-28 13:17:25
本文介绍了在 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 文件?

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

发布评论

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

>www.elefans.com

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