使用 asp.net mvc 返回文件?
我有一个自定义的 IHttpHandler,胖客户端使用它来使用 url 下载文件,例如
http://url.ashx?id=123&version=456
代码处理程序基本上以
context.Response.WriteFile(myLocalServerPath);
Is it possible to replacement this using the generic asp.net mvccontroller pattern 结尾?
I have a custom IHttpHandler which is used by thick clients to download files using a url such as
http://url.ashx?id=123&version=456
the code handler basically ends with
context.Response.WriteFile(myLocalServerPath);
Is it possible to replace this using the typical asp.net mvc controller pattern ?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
发布评论
评论(2)
π浅易2024-09-20 23:40:19
来自这个网站但经过简化:
public FileResult Download()
{
string filename = "test.pdf";
string contentType = "application/pdf";
//Parameters to file are
//1. The File Path on the File Server
//2. The content type MIME type
//3. The parameter for the file save by the browser
return File(filename, contentType,"Report.pdf");
}
~没有更多了~
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
在操作中:(
或者更具体的 MIME 类型(如果已知))
In an action:
(Or a more specific MIME type if known)