MvcRazorToPdf
MvcRazorToPdf copied to clipboard
How to download file using ajax call?
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" };
Right now i am using window.location.href = url;. i need to do some other database updates after downloading how to do ?
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.