The generation of a pdf should be done on the server side, in the code that you have invoked an action of the asp.net mvc controller, but it is not necessary to send any FormData
just send a simple json
The issue is not like invoking the action since with the $ .ajax you can do it without problems, but how you receive the pdf generated on the server
The article describes a possible way
Generate and Download PDF file on Ajax Post method, C #
the idea is that using ajax you invoke a controller action
[HttpPost]
public ActionResult Save()
{
// write code here to save the data in database.
var fName = string.Format("MYPDF-{0}.pdf", DateTime.Now.ToString("s"));
using (var ms = new MemoryStream())
{
using (var document = new Document(PageSize.A4, 50, 50, 15, 15))
{
PdfWriter.GetInstance(document, ms);
document.Open();
document.Add(new Paragraph("HelloWorld"));
document.Close();
}
var bytes = ms.ToArray();
Session[fName] = bytes;
}
return Json(new { success = true, fName }, JsonRequestBehavior.AllowGet);
//return View();
}
public ActionResult DownloadInvoice(string fName)
{
var ms = Session[fName] as byte[] ;
if(ms == null)
return new EmptyResult();
Session[fName] = null;
return File(ms, "application/octet-stream", fName);
}
so that from the client you use
$("#btnSave").click(function () {
$.ajax({
type: 'POST',
url: "/home/save",
dataType: "json",
success: function (resultData)
{
if (resultData.success) {
window.location = "/home/DownloadInvoice" + "?fName=" + resultData.fName;
}
}
});
})
when using the window.location, download the pdf that is temporarily in the Session