Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
504 views
in Technique[技术] by (71.8m points)

c# - Downloading files from the database in Asp.Net Mvc

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?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)
<%= Html.ActionLink("download file", "download") %>

and in your action:

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

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...