I am working on angularjs ,mvc and c#. I need to generate csv file.
From c# code I am returning a Json list as below.
public JsonResult methodname()
{
return Json(TEST, JsonRequestBehavior.AllowGet);
}
In angular js i am using the following code,
var req = {
method: 'POST',
url: ' ,
contentType: "application/json"
}
$http(req).success(function (data) {
if (data) {
var dataUrl = 'data:text/csv;utf-9,' + encodeURI(data));
var link = document.createElement('a');
angular.element(link)
.attr('href', dataUrl)
.attr('download', "fileName.csv") // Pretty much only works in chrome
link.click();
Csv file is downloaded, but data in csv is
[object Object],[object Object]
The actual data passed from c# is as below
0: {AccountNumber: "11910760", AccountName: "1st Central"} 1: {AccountNumber: "11910760", AccountName: "2020 LEGAL LIMITED"}
I need an output like this
11910760,1st Central
11910760,2020 LEGAL LIMITED
Any help is appreciated.
Thanks