I am LinqToCsv and this tutorial to convert my data to a downloadable csv files.
WHAT HAVE I DONE :
I have created an action like the one shown below:
public FileResult GetReportCsvData(MyFilterModel model)
{
var data = _myService.GetMyData(model);
var fileName = String.Format("{0}_{1}_{2:yyyy_MMM_d}", Helpers.GetLoggedInUserName(), "Ad-Reports", DateTime.Today) + ".csv";
var outputFileDescription = new CsvFileDescription { SeparatorChar = ',', FirstLineHasColumnNames = true };
var cc = new CsvContext();
cc.Write(data, "c:/" + fileName, outputFileDescription);
return File("c:/" + fileName, System.Net.Mime.MediaTypeNames.Application.Octet, fileName);
}
and using the following jquery I get my csv file:
exportCsv: function () {
var data = this.getFilters();
var url = '/MyController/GetReportCsvData';
var form = document.createElement('form');
form.action = url;
form.method = 'POST';
form.style.display = 'none';
for (i in data) {
if (data[i] != "") {
var inputElement = document.createElement('textarea');
inputElement.name = i;
inputElement.value = data[i];
form.appendChild(inputElement);
}
}
document.body.appendChild(form);
form.submit();
}
This works and I get the csv file with the download prompt.
WHAT DO I WANT
Here with the current code I have to save the file on my server (C:/filename) and then return its File object.
I do not want to save it on my server.
What changes do I have to make to achieve this ?