Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

how to handle respond of fileResult in Javascript

The controller:

       [HttpGet]
    public FileResult Get()
    {
       //execute sql
        using (XLWorkbook wb = new XLWorkbook())
        {
            wb.Worksheets.Add(dt, "file");
            using (MemoryStream stream = new MemoryStream())
            {
                wb.SaveAs(stream);
                return File(stream.ToArray(), "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet", "Data.xlsx");
            }
        }
    }

how i handle this to javascript to download it from page?

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

How about calling the fileresult url in a new page? Like;

window.open("/FileController/Get");

Browser will detect the FileResult and download will start.

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading