title: How to stream text to the browser in ASP.net MVC 4?
body: <p>I'm trying to figure out how to make ASP.net MVC 4 send data back to the browser during a long-running operation.  Because I've never done this before, I am starting with a simple example:</p>
  
  <pre><code>public void Index()
  {
      Response.Write("&lt;p&gt;Hello, world! Counting to 5!&lt;/p&gt;");
      for (int i = 0; i &lt; 5; i++)
      {
          Thread.Sleep(1000);
          Response.Write("&lt;p&gt;" + i + "&lt;/p&gt;");
          Response.Flush();
      }
  }
  </code></pre>
  
  <p>I would think that this code should immediately send "Hello, world! Counting to 5!" to the browser and then send one digit per second afterwards until it reaches five.</p>
  
  <p>However, when I run this code, it takes five seconds and all the text is output at once.</p>
  
  <p>I thought that the Response.Flush() method was supposed to allow you to send data to the browser incrementally.</p>
  
  <p>How can I make this work?</p>