views:

100

answers:

3

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?

A: 

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.

mookid8000
Thank you for the reply, it just want i want!
A: 

I guess you also can point a iframe element from HTML to the target file url directly.

codemeit
A: 

Alternatively you could write your own ActionResult that writes the contents of the file to Response.Output (could potentially avoid loading the entire file into memory at once albeit it might not be a big issue).

veggerby