2

I'm writing a asp.net MVC site and I have written some extensions to the Html class to generate some html for me.

From within the extension method is it better to write directly to the Response.Output stream or have the extension method return a string?

What are the advantages / disadvantages of using the Reponse.Output stream directly from a View.

Usage example:

<%= Html.GenerateHtml() %>

vs.

<% Html.GenerateFoo() %>

From within the GenerateFoo() method I can writ directly to the output streem with the following

... 
helper.ViewContext.HttpContext.Response.OutputStream.Write()
...

2 Answers 2

3

Returning a string gives you the option of modifying/inspecting/capturing the result before it gets dumped to Response.Write().

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

Comments

0

First, I wouldn't use OutputStream for text output, I would use Response.Write().

Second, returning a string to <%= calls Response.Write() anyhow (look at the compiled output of an ASPX in your Temp ASP.NET files folder sometime).

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.