title: MVC Controller Using Response Stream
body: <p>I'm using MVC 3 I would like to dynamically create a CSV file for download, but I am unsure as to the correct MVC orientated approach.</p>
  
  <p>In conventional ASP.net, I would have written something like:</p>
  
  <pre><code>Response.ClearHeaders();
  Response.ContentType = "text/csv";
  Response.AddHeader("content-disposition", attachment;filename='Test.csv'");
  Response.Write("1,2,3");
  Response.End();
  </code></pre>
  
  <p>I have looked at the <code>ContentResult</code> action but it appears that I would need to create the result as a string, i.e.</p>
  
  <pre><code>return Content(myData, "text/csv");
  </code></pre>
  
  <p>I could, I suppose, build a string, but since these files could be several thousand lines long, this seems inefficient to me.</p>
  
  <p>Could someone point me in the right direction?  Thanks.</p>