title: Web API return csv file
body: <p>I need to get a csv file from web api controller. I can not get "Save As" dialog to show up. Only text output shows up on the page. I tried both, calling Export from jquery and also plain old html  </p>
  
  <p>Controller:</p>
  
  <pre><code>[System.Web.Http.HttpGet]
  public HttpResponseMessage Export()
  {
      StringBuilder sb = new StringBuilder();
      IEnumerable&lt;CustomerDiscount&gt; list = this.subscriberRepository.GetSubscribers();
  
      foreach (CustomerDiscount item in list)
      {
          sb.AppendFormat(
              "{0};{1};{2};",
              item.CustomerName,
              item.CustomerNumber,
              Environment.NewLine);
      }
  
      MemoryStream stream = new MemoryStream();
      StreamWriter writer = new StreamWriter(stream);
      writer.Write(sb.ToString());
      writer.Flush();
      stream.Position = 0;
  
      HttpResponseMessage result = new HttpResponseMessage(HttpStatusCode.OK);
      result.Content = new StreamContent(stream);
      result.Content.Headers.ContentType =
          new MediaTypeHeaderValue("text/csv");
      result.Content.Headers.ContentDisposition = new ContentDispositionHeaderValue("attachment") { FileName = "Export.csv" };
      return result;
  }
  </code></pre>
  
  <p>EDIT:
  added this line:</p>
  
  <pre><code>result.Content.Headers.ContentDisposition = new ContentDispositionHeaderValue("attachment") { FileName = "Export.csv" };
  </code></pre>
  
  <p>still doesn't work</p>
  
  <p>I call it like this:</p>
  
  <pre><code>&lt;a id="export" href="/Relay/Billing/Export" class="btn btn-primary"&gt;Export&lt;/a&gt;
  </code></pre>
  
  <p>and also tried it like this:</p>
  
  <pre><code>$("#export").click(function () {
      $.post("/Relay/Billing/Export", { type: $("#discountType").val() })
        .done(function (data) {
        });
  });
  </code></pre>
  
  <p>Still no Save As box</p>