Download byte array data using jQuery AJAX in ASP.Net Core MVC

on Sep 27, 2022 03:29 AM

How to download byte array data from jQuery Ajax.

I have one api which return me data as Byte[], i want to download that data in ajax jquery response.

How can i download that file.

public IActionResult DownloadProviderDocument(DownloadProviderDocumentModel model)
    AccountApiCall accountApiCall = new AccountApiCall(Configuration["PrescriptionAPI"]);            
    var Response = accountApiCall.PostAPIcall<ProviderDownloadDocumentResponseModel>(model, "provider/documentdownload", HttpContext.Request.Cookies["Token"].ToString());           
    return Json(Response);
$('#dataexample tbody').on('click', 'a.btndownloadlink', function () {                              
    var $row = $(this).closest('tr');
    var data =  $('#dataexample').DataTable().row($row).data();                 
         type: "POST",
         url: '@Url.Action("DownloadProviderDocument","Provider")',
         data: {UserId: data.userId,File:data.fileName },                         
         success: function (response) {
                 heading: 'Success',
                 text: 'Document Downloaded  Successfully!.',
                 showHideTransition: 'slide',
                 icon: 'success'
            // window.location.reload();
             var table=('#dataexample').Datatable();
             //add second tab active class

the json return data like below.


Download FREE API for Word, Excel and PDF in ASP.Net: Download
on Sep 27, 2022 03:37 AM