Menu Close

Download File Using Jquery Ajax In Asp.net Mvc Extra Quality Today

Your controller returns a FileResult with the appropriate MIME type.

[HttpGet] public ActionResult Download(string fileName) { string fullPath = Path.Combine(Server.MapPath("~/temp"), fileName); return File(fullPath, "application/vnd.ms-excel", "Report.xlsx"); } Use code with caution. Best Practices & Troubleshooting download file using jquery ajax in asp.net mvc

[HttpPost] public ActionResult ExportReport(int id) { byte[] fileBytes = System.IO.File.ReadAllBytes(Server.MapPath("~/App_Data/Report.pdf")); string fileName = "Report.pdf"; return File(fileBytes, "application/pdf", fileName); } Use code with caution. Your controller returns a FileResult with the appropriate