在渲染ASP.NET MVC视图的HTML文件? [英] Render HTML file in ASP.NET MVC view?

查看:488
本文介绍了在渲染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 为this.It是呈现局部特殊的helper方法意见。相反,你可以添加一个动作是这样的:

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");
}

和您可以从查看使用的 Html.Action helper方法:

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文件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆