Download a File by POST (HttpPost action) on ASP.NET MVC controller action using Javascript

后端 未结 1 858
梦谈多话
梦谈多话 2021-01-25 02:28

Initially, my controller action accepts GET. When my data grew, I was forced to move to POST method to be able to send larger data. My controller action is as follows:



        
相关标签:
1条回答
  • 2021-01-25 03:09

    Update: I realized that my original answer about AJAX was not entirely accurate since there is no way to return a file from an AJAX call. I suggest that you look at this SO question: Download Excel file via AJAX MVC. I believe @CSL has a good answer that is similar to what you want.

    My answer is not plain javascript. This is an AJAX call in jQuery on how it could be done there:

    $.ajax({
        url: urlControllerAction,
        type: 'POST',
        cache: false,
        data: //your parameter data here
    })
    .done(
        function(result, textStatus, jqXHR) {
            //do something with the "result"
        }
    )
        .fail(
            //what should be done if something goes wrong
        );
    

    0 讨论(0)
提交回复
热议问题