tags:

views:

719

answers:

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()
...
A: 

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).

chadmyers
+2  A: 

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

Todd Smith