views:

24

answers:

3

I have a some html fragment in memory that I need to render using RenderAction. For instance my action method looks something like this:

var html = "some html code

How do I make it render this html by using RenderAction, I don't want to create a view file because this is dynamic html. And I can't use any of the file results because this is not coming from a file. What other ways are there to accomplish this?

A: 

Immediately I can think of two options:

1) You can read this HTML string into a stream and then serve it back via FileResult (stream, "text/html")

2) You read this HTML string into a model property and output it through a view via <%= Model.MyDynamicHtml %>

The 1) is probably easier.

Developer Art
A: 

That is it number 2, works for me. Can you show me the code for number one. FileResult is a base class and the it is a FileStream what is needed, and I can not create a FileStream without a filepath right?

Proscopio
This is not an answer -- you should post comments as comments.
Ian Henry
A: 

Check out the ContentViewResult, or the shortcut return Content(string html)

Wyatt Barnett