1

I have the next action in the controller:

[HttpPost]
public ActionResult LoadPdf(Guid? staffId, Guid? stageId, TaskFilterViewModel filter)
{
   // my horrible piece of s***
   return File(pdf.ToArray(), "application/pdf", filename);
}

On the client side I have JSON object that I pass as a parameter to actions in constroller (all actions have same signatures). But how make in ajax if I need to download a file. I can't use a simple redirect to this action because I need to pass JSON.
This is a simple function when I just need to update a content on the page:

function applyFilter() {
    var data = getFilterData();
    var dataStr = JSON.stringify(data);
    var url = 'some url';

    $.ajax({
        url: url,
        type: 'POST',
        data: dataStr,
        contentType: "application/json;charset=utf-8",
        success: function (response) {},
        error: function () {},
        timeout: 15000
    });
}

But how to make it for a file downloading?

Denis Sologub
  • 7,277
  • 11
  • 56
  • 123
  • 1
    The answer I posted to the duplicate question should help you as well. If you end up needing additional help, open a new question with the specific issues you run into. – Chris Pratt Feb 10 '17 at 14:23
  • @ChrisPratt, thank you very much! It helped me really, I did not find this thread. – Denis Sologub Feb 10 '17 at 14:32

0 Answers0