Render HTML file in ASP.NET MVC view?
Follow these steps
- Create a view in
~/views/shared
folder. give it nametest.cshtml
. - Copy the content of HTML in it.
- Use
Html.Partial("test")
on page to render the html of that view.
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");
}
And you can call it from your View
with using Html.Action
helper Method:
@Html.Action("GetHtmlPage","controllername", new { path = "~/Test/main.html" })
I think it's a better solution:
Use WriteFile
from the Response
object
@Response.WriteFile(pathToMyHtmlFile)
taken from here