I have Image column in Ms Sql Database.Pdf files are in that column.
public ActionResult Index()
{
DatabaseEntities _ context = new DatabaseEntities();
var PdfFile = _context.FileTable.where(p=>p.Id==1).Select(s=>s.FileData).FirstOrDefault();
return view();
}
I select file's Byte and set it to "var PdfFile"
But i am not sure how can i call PdfFile in view and display inside html div in asp.net mvc ?
Any help will be greatly appreciated.
Thanks.
You have make use of ViewData. Although I'm not sure how exactly you'er gonna display the pdf but to answer the question add this in your method:
ViewData["PDF"] = PDFFile;
and in the razor you can get it this way:
@var getData = ViewData["PDF"];
To Display it, first convert it to base64:
<object data="data:application/pdf;base64,@System.Convert.ToBase64String((Byte[])ViewData["PDF"])" type="application/pdf" width="500px">
<embed src="data:application/pdf;base64, @System.Convert.ToBase64String((Byte[])ViewData["PDF"])" type="application/pdf" />
</object>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With