c# mvc return JSON or File from AJAX call

后端 未结 4 818
花落未央
花落未央 2021-01-14 00:30

I have something like this in my View:

        var url = \'@Url.Action(\"DownloadZip\", \"Program\")\' + \'?programNums=\' + selectedRow;

        $.ajax({
          


        
4条回答
  •  不思量自难忘°
    2021-01-14 01:17

    Have you considered passing back JSON with a file Url?

    If the file is successfully found/created. Send back a JSON result with the link to the file. Then in javascript use windows.location to retrieve the file. When there is an error, the JSON result will contain the error information and this info can be displayed to the user. For this to work, you'll need to create another endpoint (action) that can stream the file.

提交回复
热议问题