来自数据库的pdf文件以在asp.net MVC中查看 [英] Pdf file from database to view in asp.net mvc

查看:98
本文介绍了来自数据库的pdf文件以在asp.net MVC中查看的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在Sql数据库中有 Image 列.Pdf文件在该列中.

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();
}

我选择文件的字节并将其设置为" var PdfFile"

I select file's Byte and set it to "var PdfFile"

但是我不确定如何在asp.net mvc的html div中查看和显示PdfFile吗?

But i am not sure how can i call PdfFile in view and display inside html div in asp.net mvc ?

任何帮助将不胜感激.

谢谢.

推荐答案

您已经使用了ViewData.尽管我不确定您将如何显示pdf,但是要回答问题,请在您的方法中添加它:

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"];

要显示它,首先将其转换为base64:

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>

这篇关于来自数据库的pdf文件以在asp.net MVC中查看的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆