MvcRazorToPdf icon indicating copy to clipboard operation
MvcRazorToPdf copied to clipboard

How to download file using ajax call?

Open tvrajja opened this issue 8 years ago • 2 comments

How to download file using ajax call? i want to return Json(new { success = "Valid" }, JsonRequestBehavior.AllowGet);

ie. how to convert the below line in actioncontroller.

return new PdfActionResult(pdfres, (writer, document) => { document.SetPageSize(new Rectangle(PageSize.A4)); document.NewPage(); }) { FileDownloadName = "ElanWasHere.pdf" };

tvrajja avatar May 02 '16 02:05 tvrajja

Right now i am using window.location.href = url;. i need to do some other database updates after downloading how to do ?

tvrajja avatar May 05 '16 01:05 tvrajja

I can't pretend I know this plugin well enough to suggest a solution directly using it, but I'm pretty sure there isn't a supported method, as I'm pretty sure you're hitting a limitation of current browser tech.

My first thought on your particular situation is not to use an AJAX call - just go to the URL like you already are, but pass some information to the controller you're hitting in the URI params and have that controller do the additional processing when the parameters are present.

So just process the other database updates in the controller that generates the pdf (as mentioned).

It's possible you could also load the file in a hidden <iframe> and use that frame's onload event to run your other AJAX calls to update your database or whatever, but that seems a little extra-complicated to me.

[EDIT] sorry for necromancy, but maybe my suggestions will help someone else, since this person obviously solved their problem since then.

FireSBurnsmuP avatar May 19 '17 14:05 FireSBurnsmuP