从Asp.Net Mvc中的数据库下载文件 [英] Downloading files from the database in Asp.Net Mvc

查看:81
本文介绍了从Asp.Net Mvc中的数据库下载文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我将文件存储在数据库中,单击按钮时需要下载文件。

我可以通过action方法获取文件内容(二进制)。但是如何将其作为文件返回给用户?

I'm storing my files in the database and need to download a file when button clicked.
i can get the File content (Binary) in the action method. But how to return it as a file to the user?

推荐答案

<%= Html.ActionLink("download file", "download") %>

,然后按您的操作:

public ActionResult Download() 
{
    byte[] contents = GetFileContentsFromDatabase();
    return File(contents, "image/jpeg")
}

这篇关于从Asp.Net Mvc中的数据库下载文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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