I'm currently working on an Asp.Net MVC project and I have a piece of code in my View that looks like this:
$.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");
}
});
Within the MyAction
method, I have the following code:
[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");
}
I am wondering how I can display the PDF content directly within a DIV element or even download it without displaying it. Any suggestions on how to achieve this?