【发布时间】:2022-02-27 12:56:51
【问题描述】:
我一直在阅读和解决下载和上传文件到数据库的问题!我刚刚完成了上传工作,所以现在我将我的文件以二进制形式保存在数据库中!我也在视图中显示名称:
@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>
我的模特:
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; }
}
现在我需要的是为每个项目设置一个下载按钮,这将触发下载所选文件的 c# 操作...
感谢任何帮助!
【问题讨论】:
-
在您的控制器中创建一个返回 File(...) 的操作
-
这是一个link,关于从数据库中检索文件。
标签: c# asp.net-mvc asp.net-core