Home > Software design >  how to handle respond of fileResult in Javascript
how to handle respond of fileResult in Javascript

Time:07-28

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?

CodePudding user response:

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

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

Browser will detect the FileResult and download will start.

  • Related