0

I have an ASP.NET MVC controller to export an Excel file:

public ActionResult exportExcelBankData(BankDataViewModel viewModel) 
{
    List<BankDataViewModel> bankDatas = (List<BankDataViewModel>)Session["bankDatas"];
    bankDatas = bankDatas.OrderBy(x => x.completeLoading).ToList();

    using (var package = new ExcelPackage()) 
    {
        var stream = new MemoryStream();
        string fileName = "bankData.xlsx";
        string contentType = "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet";

        // fill rows and columns

        package.SaveAs(stream);
        stream.Position = 0;

        return File(stream, contentType, fileName);
    }
}

And here my AngularJs function to hit the controller:

 labAnalysisService.exportExcel = function (val, obj) {
    return $http.get( val, //url to controller
      { params: obj, //parameter
        headers: { 'Accept': 'application/json' } 
      });
}

I am still unable to export the Excel.

Any suggestions?

1
  • is end point hitting ? if yes what do you get in response ? Commented Apr 18, 2018 at 6:03

1 Answer 1

0

A File returned with ajax call will not be downloaded, you have to make following changes. Make request of the excel download by opening a new window of browser through java script like this

         window.open(
        "Controller/Action?args=" + encodeURIComponent(val),
        "_blank");

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.