title: How to download a file through ajax request in asp.net MVC 4
body: <p>Below is my code : </p>
  
  <pre><code>ActionResult DownloadAttachment(student st)
  {          
      var file = db.EmailAttachmentReceived.FirstOrDefault(x =&gt; x.LisaId == st.Lisaid);
  
      byte[] fileBytes = System.IO.File.ReadAllBytes(file.Filepath);
      return File(fileBytes, System.Net.Mime.MediaTypeNames.Application.Octet, file.Filename);                 
  }
  </code></pre>
  
  <p>This is the script which i'm using</p>
  
  <pre><code>$(function () {
      $("#DownloadAttachment").click(function () {
          $.ajax({
              url: '@Url.Action("DownloadAttachment", "PostDetail")',
              contentType: 'application/json; charset=utf-8',
              datatype: 'json',
              type: "GET",
              success: function () {
                  alert("sucess");
              }
          });    
      });
  });      
  </code></pre>
  
  <p>How to return the file for download pursing above code?</p>