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?