用户只需单击按钮即可下载pdf文件。 [英] user to be able to download a pdf file with a click of a button.

查看:108
本文介绍了用户只需单击按钮即可下载pdf文件。的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个MVC项目,我希望用户能够通过点击按钮下载pdf文件。

I have an MVC project where I'd like the user to be able to download a pdf file with a click of a button.

推荐答案

参考 - < a href =http://stackoverflow.com/a/730775/1099247>如何从MVC控制器提供下载文件? [ ^ ]。

Refer - How can I present a file for download from an MVC controller?[^].
引用:

从您的操作返回FileResult或FileStreamResult,具体取决于文件是否存在或您是否即时创建。

Return a FileResult or FileStreamResult from your action, depending on whether the file exists or you create it on the fly.

public ActionResult GetPdf(string filename)
{
    return File(filename, "application/pdf", Server.UrlEncode(filename));
}


这篇关于用户只需单击按钮即可下载pdf文件。的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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