我正在尝试从我的angularjs代码下载mvc中的csv文件,而不是下载它显示一个页面
StatusCode: 200, ReasonPhrase: 'OK', Version: 1.1, Content: System.Net.Http.StringContent, Headers: { Content-Type: text/comma-separated-values Content-Disposition: attachment; filename=test Content-Length: 276 }
服务器端代码
ActionName("ExportToCSV")]
public HttpResponseMessage PostCSVDomainWiseReports(ReportFilterModel reportFilter)
{
var csvReport = _csvService.GetCsvReports(reportFilter);
if (csvReport.NoDataForTheDateRange)
{
return new HttpResponseMessage(HttpStatusCode.NoContent);
}
var csvValidRequestResult = new HttpResponseMessage(HttpStatusCode.OK){Content = new StringContent(csvReport.Data)};
csvValidRequestResult.Content.Headers.ContentType = new MediaTypeHeaderValue("text/comma-separated-values");
csvValidRequestResult.Content.Headers.ContentDisposition = new ContentDispositionHeaderValue("attachment"){FileName = csvReport.FileName};
return csvValidRequestResult;
}
Angular js code
$scope.getCsvReports = function () {
window.open($scope.getReportUrl("csv"), '_blank', '');
};