c# - Using CSVHelper to output stream to browser but unable to save file -



c# - Using CSVHelper to output stream to browser but unable to save file -

i trying accomplish poster in this question trying except browser (chrome) doesn't effort download .csv file or nowadays user download box. using http request , code virtually identical in question above. i'm using fiddler monitor traffic , can see .csv file stream in response, browser seems ignore , can't work out why...

here current implemenation (base on @mattthrower's question):

i create ajax phone call mvc controller:

$("#exporttocsvlink").click(function () { $.ajax({ type: "get", url: window.project.common.routes.urls.exportchartdatatocsv, data: { parameterid: parameter.parameterid } }); });

the mvc controller processes csv export , returns filestreamresult

public filestreamresult exportchartdatatocsv(int parameterid) { list<testviewmodel> info = _commonservice.getdata(parameterid); var result = writecsvtomemory(data); var memorystream = new memorystream(result); homecoming new filestreamresult(memorystream, "text/csv") { filedownloadname = "export.csv" }; } public byte[] writecsvtomemory(ienumerable<testviewmodel> data) { using (var memorystream = new memorystream()) using (var streamwriter = new streamwriter(memorystream)) using (var csvwriter = new csvwriter(streamwriter)) { csvwriter.writerecords(data); streamwriter.flush(); homecoming memorystream.toarray(); } }

c# asp.net-mvc csvhelper

Comments

Popular posts from this blog

php - Android app custom user registration and login with cookie using facebook sdk -

django - Access session in user model .save() -

php - .htaccess Multiple Rewrite Rules / Prioritizing -