2010-03-12 43 views
5

我正在將我的文件存儲在數據庫中,並且在點擊按鈕時需要下載文件。
我可以在操作方法中獲取文件內容(二進制)。但如何將其作爲文件返回給用戶?從Asp.Net數據庫中下載文件Mvc

回答

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

,並在你的行動:

public ActionResult Download() 
{ 
    byte[] contents = GetFileContentsFromDatabase(); 
    return File(contents, "image/jpeg") 
} 
2
return new FileContentResult(byte[], contentType) 
+0

或只是'返回文件(...)' – 2010-03-12 15:51:45