0

The following code writes successfully the PDF content to my browser window, so I see it as tokenised characters starting with %PDF

But I want it to just automatically download to the browser then the browser will prompt the user, save or open etc

function pricingSummary(sReportName,sType) {

    var url = '/Report/PricingByMDS';


    var data = {
        searchSPID: $('#SearchSPID').val().toString(),
        searchPremise: $('#SearchPremise').val().toString(),
        searchPostcode: $('#SearchPostcode').val().toString(),
        optSupplyPointStatus: $("input[name='optSupplyPointStatus']:checked").attr("id"),
        optVacant: $("input[name='optVacant']:checked").attr("id"),
        optOurSpids: $("input[name='optOurSpids']:checked").attr("id"),
        searchCompany: $('#SearchCompany').val().toString(),
        searchLP: $('#SearchLP').val().toString(),
        sType: sType,
        sReportName: sReportName
    };

    $("#ResultsList").load(url, data, function () {

    });

}
John
  • 1,459
  • 4
  • 21
  • 45
  • possible duplicate of [Download a file by jQuery.Ajax](http://stackoverflow.com/questions/4545311/download-a-file-by-jquery-ajax) – DavidG Oct 10 '14 at 09:57
  • Often the easiest way is to not use ajax. Attempting to navigate to a URI that returns a PDF will usually trigger the browser's download dialog without additional effort on your part. Search for "asp.net mvc return pdf" and you will get lots of examples. – David Godwin Oct 10 '14 at 18:11
  • Yeah, I since realised (after your comment) i'd did this before by returning a FileStreamResult object from a controller. Using JQuery is the wrong approach for the last step of the operation, messy and the wrong solution, cheers – John Oct 11 '14 at 00:41

0 Answers0