【问题标题】:Downloading files from the database in Asp.Net Mvc从 Asp.Net Mvc 中的数据库下载文件
【发布时间】:2010-03-12 15:46:56
【问题描述】:

我将文件存储在数据库中,并且需要在单击按钮时下载文件。
我可以在操作方法中获取文件内容(二进制)。但是如何将其作为文件返回给用户呢?

【问题讨论】:

    标签: c# .net asp.net-mvc


    【解决方案1】:
    <%= Html.ActionLink("download file", "download") %>
    

    在你的行动中:

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

    【讨论】:

      【解决方案2】:
      return new FileContentResult(byte[], contentType)
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2021-10-02
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多