简体   繁体   中英

What is the best practice for using ASP.NET MVC to render lots of html or text files?

I have a lot of html pages, but I don't know how to display them through the asp.net mvc view.

I buid a view as my template and use asp.net mvc to insert html into the template and then render it.

But the question is that I must use FileStream to read the raw html-based files into memroy and then put it into view template, like ViewData["content"] = ???.

I just want to know if there are some other better ways to render static html files to the browser.

Did i describe the question clearly?

I guess you could do something like this:

using(var file = new StreamReader(htmlFileName))
{
    return Content(file.ReadToEnd());
}

Note that the mime type automatically defaults to text/html, but you could optionally specify which mime type headers should be sent by supplying the type as an additional argument to the Content method.

我想您也可以直接将HTML中的iframe元素指向目标文件url。

或者,您可以编写自己的ActionResult,将文件的内容写入Response.Output(可以避免将整个文件立即加载到内存中,尽管这可能不是大问题)。

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM