Reputation: 31
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?
Upvotes: 3
Views: 7521
Reputation: 15673
Check out the ContentViewResult
, or the shortcut return Content(string html)
Upvotes: 8
Reputation:
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.
Upvotes: 0