I am using MVC to display the PDF content in View, but it is not rendering properly.
Controller Action:
[HttpPost]
public ActionResult GetDocumentContent()
{
byte[] result;
result = System.IO.File.ReadAllBytes(@"C:\test.pdf");
Response.AppendHeader("Content-Disposition", new System.Net.Mime.ContentDisposition
{
FileName = "document.pdf",
Inline = true,
}.ToString());
return File(result, "application/pdf");
}
Jquery:
var url = "/DocumentContent/GetDocumentContent";
var self = this;
$.post(url, null,function (data) {
debugger;
var obj = $('<object type="application/pdf" width="100%" height="100%" border="2"></object>');
obj.attr('data', data);
$('#divContainer').append(obj);
});
What is the mistake in this code? How to display the PDF stream in View?