title: Download excel file from page via WebApi call
body: <p>I'm trying to send a 9MB <code>.xls</code> file as a response from web api controller method.  The user will click a button on the page and this will trigger the download via the browser.</p>
  
  <p>Here's what I've got so far but it doesn't work however it doesn't throw any exceptions either.</p>
  
  <pre><code>[AcceptVerbs("GET")]
  public HttpResponseMessage ExportXls()
  {
      try
      {
          byte[] excelData = m_toolsService.ExportToExcelFile();
  
          HttpResponseMessage result = new HttpResponseMessage(HttpStatusCode.OK);
          var stream = new MemoryStream(excelData);
          result.Content = new StreamContent(stream);
          result.Content.Headers.ContentType = new MediaTypeHeaderValue("application/octet-stream");
          result.Content.Headers.ContentDisposition = new ContentDispositionHeaderValue("attachment")
          {
              FileName = "Data.xls"
          };
          return result;
      }
      catch (Exception ex)
      {
          m_logger.ErrorException("Exception exporting as excel file: ", ex);
          return Request.CreateResponse(HttpStatusCode.InternalServerError);
      }
  }
  </code></pre>
  
  <p>Here is the coffeescript/javascript jquery ajax call from a button click in the interface.</p>
  
  <pre><code>$.ajax(
      url: route
      dataType: 'json'
      type: 'GET'
      success: successCallback
      error: errorCallback 
      )
  </code></pre>
  
  <p>Now that I think about it perhaps the dataType is wrong and shouldn't be json...</p>