i want to download a model in an excel file using angular, this is function the code of my service:
getExcelReport(data: myModel[]): Observable<Blob> {
let params = new HttpParams()
.set('myParam', JSON.stringify(data));
return this.Http.get(this.url + '/MyController/GetExcelReport', { params: params, observe: "body", responseType: "blob" });
when i call it i get an error: 415 (Unsupported Media Type). Any i idea of the correct syntax to use? Thanks
Thank you for your help, yes i want only download it.I found this solution:
getExcelReport(data: myModel[]): void {
const url: string = this.url + '/MyController/GetExcelReport';
this.Http.post(url, data, { responseType: 'blob' })
.subscribe((response: Blob) => saveAs(response, `report.xlsx`));
}
In API:
[HttpPost] [Route("GetExcelReport")] public async Task<IActionResult> GetExcelReport([FromBody] IList<myModelType> myModel)
It worked for me
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.