'How to download files from a database, and get them as image in Asp.net core MVC?

I have been reading and working around downloading and uploading files to database! I just made upload work, so now i save my files in Binary in the database! Also i display the name in the View :

@model IEnumerable<RH_Files>

<div class="tableContainer">
    <table class="table table-striped">
        <thead>
            <tr>
                <th>
                    @Html.DisplayNameFor(p => p.Name)
                </th>
            </tr>
        </thead>
        <tbody >
            @foreach (var item in Model)
            {
              <tr>
                  <td>
                      @Html.DisplayFor(model => item.Name)
                  </td>
              </tr>
            }
        </tbody>
    </table>
</div>

as you can see : enter image description here

my model:

 public class RH_Files
    {
        [Key]
        public int id { get; set; }
        public string Name { get; set; }
        public string ContentType { get; set; }
        public Byte[] Data { get; set; }
    }

Now what i need, is to have a download button for each item, that will trigger a c# action that downloads the file selected...

Any help is appreciated!!



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source