How to generate and download excel from a large volume of data in ASP.Net MVC?

Asked

Viewed 60 times

1

Hello I have web application that provides a download of contents of the database in excel format, I am using in my controller a method of type Fileresult. Below abridged version of the code.

Simple download link

                    <div>
                    <a href="@Url.Action("DownloadExcel","DeliveryReport")">Download Excel</a>
                </div>

Function of the controller

        public FileResult DownloadExcel(DeliveryReportViewModel model)
        {
           var dto = Service.GetDto();
           byte[] filecontent = ConverToExcel(dto);
           return File(filecontent, ExcelExportHelper.ExcelContentType, 
           ExcelExportHelper.GenerateFileName(Resources.DeliveryReport));
        }

It works perfectly until certain amount of records, the problem is when there is a large volume of data. The request time does not last more than one minute so when it exceeds this waiting time an error is returned to me even with the controller giving continuity to the data process. How could I leave the request lasting as long as it took to download the file? Or who knows leaving this process in the background while the user continues to use the system?

1 answer

0

You can change the flow so that in the route the usurer asks the generation of the file and when finished you forward an email to it with a link to download the file.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.