title: How to implement file download with AJAX and MVC
body: <p>I would like to provide a file download operation by using the jQuery AJAX call with some params under MVC</p>
  
  <p>Example</p>
  
  <pre><code>(javascript)
  function DoDownload(startDate) {
  
    $.ajax({ 
       url:"controller/GetFile/",
       data: {startDate:startDate}
       ...
    });
  
  }
  
  C# Controller Code
  
   public void GetFile(string startDate) {
  
    var results = doQueryWith(startDate);
  
     // Create file based on results
     ....
     // How do I tell the server to make this a file download??
   }
  </code></pre>
  
  <p>I typically would just make my file download a link such as:</p>
  
  <pre><code>&lt;a h r e f="mycontroller/getfile/1"/&gt;Download&lt;/a&gt;
  </code></pre>
  
  <p>but in the case above the date will be dynamic.</p>
  
  <p>If I don't use ajax, what would be a preferred way to pass in the params to the MVC controller using javascript?</p>
  
  <p>Example:</p>
  
  <pre><code>window.location  = "mycontroller/GetFile/" + $("#fromDate").val();
  </code></pre>
  
  <p>assuming the date is 12-25-2012</p>
  
  <p>Would this produce </p>
  
  <pre><code>mycontroller/GetFile/12/25/2012
  </code></pre>
  
  <p>would MVC treat this as three params?</p>