How to implement file download with AJAX and MVC

后端 未结 4 1776
Happy的楠姐
Happy的楠姐 2021-02-07 20:06

I would like to provide a file download operation by using the jQuery AJAX call with some params under MVC

Example

(javascript)
function DoDownload(start         


        
4条回答
  •  北荒
    北荒 (楼主)
    2021-02-07 20:56

    Your controller action method should return a FileResult instead of void. And there is no need to do this via AJAX - in fact, you don't want to do this with AJAX. You'll need the browser involved so it knows to provide a download dialog for the user.

    See these links:

    Handling an ASP.NET MVC FileResult returned in an (jQuery) Ajax call

    File download in Asp.Net MVC 2

    I hope this helps.

提交回复
热议问题