在新标签中查看PDF

时间:2016-10-14 18:33:27

标签: c# asp.net-mvc pdf

我有一个MVC应用程序,当我点击<a>标签时,我想要显示PDF。我将文件路径和文件名传递给服务器端。当我在本地运行它渲染,但当我推送到服务器它给我一个404错误。有什么想法吗?

这是我的客户端代码,数据是文件路径:

'<a href="/OCR/ViewPDF?file=' + data + '&name=' + url + '" target=_blank>' + url + '</a>';

服务器端代码:

public FileContentResult ViewPDF(string file,string name)
    {
        string FilePath = Server.MapPath(_file);

        WebClient User = new WebClient();

        Byte[] FileBuffer = User.DownloadData(FilePath);

        if (FileBuffer != null)
        {
            Response.ContentType = "application/pdf";
            Response.AddHeader("content-length", FileBuffer.Length.ToString());
            Response.BinaryWrite(FileBuffer);
        }

    return null;

}

0 个答案:

没有答案
相关问题