简体   繁体   中英

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?

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

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

Browser will detect the FileResult and download will start.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM