Download file when clicking on file name
This example explains when there is a link to a file field and downloading the file directly from the website.
@if (!@Model.Flink285.IsEmpty){
<tr>
<td>Picture(s)</td>
<td>
@foreach(var picture in @Model.Flink285) {
<a download="@picture.F1.FileName" href="data:img/png;base64,@picture.F1" target="_blank">
<p>@picture.Name</p></a>
}
</td>
</tr>
}
when an F field is used (instead of an Flink field):
<tr>
<td width=50%>F: @Model.F227.Label</td>
<td>
<a download="@Model.F227.FileName" href="data:img/png;base64,@Model.F227" target="_blank">@Model.F227.FileName</a>
</td>
</tr>
Extra explanation on the code:
-
download="picture.F1.FileName" the name and extension of the item that will be downloaded.
-
@picture.F1 the actual picture stored in the File field (f1) in the Files table (flink285).
-
target="_blank" open a new tab to download the file.
The result looks like:
The code placed in a table:
<table class="table">
<thead>
</thead>
<tbody>
@if (!@Model.Flink285.IsEmpty){
<tr>
<td>Picture(s)</td>
<td>
@foreach(var picture in @Model.Flink285) {
<a download="picture.png" href="data:img/png;base64,@picture.F1" target="_blank">
<p>@picture.Name</p></a>
}
</td>
</tr>
}
</tbody>
</table>