I have an Asp.Net MVC project and in my View this stretch:
$.ajax({
beforeSend: function () {
LoadStart();
},
complete: function () {
LoadStop();
},
//async: false,
contentType: 'application/json, charset=utf-8',
dataType: 'json',
type: 'POST',
url: '@Url.Action("MyAction", "MyController")',
data: JSON.stringify(
{
Param1: 1,
Param2: 2
}),
success: function (data) {
$("#pdf-content").show();
// Here, fill DIV (pdf-content) with PDF.
},
fail: function () {
alert("Fail");
}
});
In MyAction
, I have:
[HttpPost]
public ActionResult MyAction(int Param1, int Param2)
{
// Code ...
MemoryStream stream = new MemoryStream();
outPdf.Save(stream);
byte[] fileContents = stream.ToArray();
return File(fileContents, "application/pdf", "myFile.pdf");
}
How can I display the PDF in DIV, or even download directly without displaying?