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?

2 Answers 2

8

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

Sign up to request clarification or add additional context in comments.

Comments

0

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.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.