0

I had a function in controller named Export

    [HttpPost]
    [ActionName("Export")]
    public async Task<FileStreamResult> Export(int a)
    {
        var fileStream = new MemoryStream();
        var contentType = "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet";

        return new FileStreamResult(fileStream, contentType);
    }

I called this function from the view using ajax.

  $('#GetDetails').click(function () {

            $.ajax({
                url: '@Url.Action("Export", "ExportNow")',
                type: 'POST',
                data: {a:1},
                success: function (result) {
                    alert('Success.');
                },
                error: function (result) {
                    alert('Failed to Export.');
                }
            });
        });

how i can open the FileStreamResult returned from the Export function (download file). Anyone please help.

Sam sam
  • 33
  • 8
  • 1
    Quite similar to what you are looking for: https://stackoverflow.com/questions/37462263/open-filestreamresult-by-ajax-as-downloaded-file – user869375 Dec 20 '17 at 09:06
  • his one was on pdf format and i need is xlsx format and his function is returning a file and i am returning a filestreamresult – Sam sam Dec 20 '17 at 09:09
  • i had tried that solution but it is not works for me, my function is taking in a parameter. – Sam sam Dec 20 '17 at 09:12

1 Answers1

-2

This works for me:

$('#GetDetails').click(function () {
    window.open('controlleraction/document?id=xx', '_blank');
});