I have created an export option (where the user will select a client from a list and press export)
<li><a href="#" onclick="LoadExport('ExportClient')"><span class="label label-info pull-right">(Download)</span><i class="fa fa-download"></i> Export Client</a></li>
function LoadReport(reportName) {
var urlExt;
switch (reportName) {
case "ExportClient":
urlExt = reportName + "?id=" + $("#clientId").val();
break;
}
$.ajax({
url: '/Exports/' + urlExt,
contentType: 'application/; charset=utf-8',
success: function (result) { ?????? },
error:function(xhr, status) { alert(status)},
type: 'GET',
dataType: 'text'
});
}
[HttpGet]
public ActionResult ExportClient(string id)
{
//do stuff
var memoryStream = new MemoryStream();
var streamWriter = new StreamWriter(memoryStream, Encoding.UTF8, 1024, true);
using (var csvWriter = new CsvWriter(streamWriter))
{
csvWriter.WriteRecords(client);
// No need to flush as the StreamWriter's Dispose takes care of that.
}
memoryStream.Position = 0;
return File(memoryStream, "text/csv", "clients.csv");
}
So this is executed successfully, but the issue is how do I return the csv on success?