MVC Export List of objects to Excel-Word-PDF-CSV-HTML-XML–Razor style

This is the second part of the demo of the Exporter  in action  – this time in MVC .

It is a little more complicated, because you need to show to the exporter the full path where to put the generated file

string filePathExport = Server.MapPath(“~/exports/a” + ExportBase.GetFileExtension((ExportToFormat)id));

All others are the same easy stuff  -add Nuget package and export in 3 lines – and all action code is 6 lines long:

            List<Electronics> list = Electronics.GetData();
            ExportList<Electronics> exp = new ExportList<Electronics>();
            exp.PathTemplateFolder = Server.MapPath("~/ExportTemplates/electronics");
            string filePathExport = Server.MapPath("~/exports/a" + ExportBase.GetFileExtension((ExportToFormat)id));
            exp.ExportTo(list, (ExportToFormat)id, filePathExport);
            return this.File(filePathExport, "application/octet-stream", System.IO.Path.GetFileName(filePathExport));





GitHub Demo at

The Nuget package is at

YouTube demo at