C# 下载PDF,don';t显示在屏幕上

C# 下载PDF,don';t显示在屏幕上,c#,asp.net-mvc,pdf,download,C#,Asp.net Mvc,Pdf,Download,我在服务器上有一个PDF文件,我想将其作为下载发送回浏览器,但它只是加载到屏幕上。这就是我正在做的: public ActionResult BillOfMaterials(Model model) { .... return File(@"C:\...(file path)...\result.pdf", "application /pdf"); } 我需要做什么才能使它实际上只是下载,而不在浏览器中打开 谢谢 这就成功了 string filepat

我在服务器上有一个PDF文件,我想将其作为下载发送回浏览器,但它只是加载到屏幕上。这就是我正在做的:

public ActionResult BillOfMaterials(Model model)
{
    ....
    return File(@"C:\...(file path)...\result.pdf", "application /pdf");
}
我需要做什么才能使它实际上只是下载,而不在浏览器中打开

谢谢

这就成功了

            string filepath = @"C:\docs\result.pdf";
            byte[] filedata = System.IO.File.ReadAllBytes(filepath);
            string contentType = System.Web.MimeMapping.GetMimeMapping(filepath);

            var cd = new System.Net.Mime.ContentDisposition
            {
                FileName = "result.pdf",
                Inline = false,
            };

            Response.AppendHeader("Content-Disposition", cd.ToString());

            return File(filedata, contentType);
这就成功了

            string filepath = @"C:\docs\result.pdf";
            byte[] filedata = System.IO.File.ReadAllBytes(filepath);
            string contentType = System.Web.MimeMapping.GetMimeMapping(filepath);

            var cd = new System.Net.Mime.ContentDisposition
            {
                FileName = "result.pdf",
                Inline = false,
            };

            Response.AppendHeader("Content-Disposition", cd.ToString());

            return File(filedata, contentType);

这就是你要找的吗?也许这对你也有帮助:这就是你想要的吗?也许这对你也有帮助: