Это полное решение для загрузки файла "alert.mp3" из каталога wwwroot / files из пользовательского контроллера.
Вид:
<form class="form-inline" method="post" enctype="multipart/form-data" asp-controller="User" asp-action="DownloadFile">
<input id="@item.ID" name="fileName" type="hidden" class="form-control" placeholder="@item.ID" value="alert.mp3">
<button type="submit" style="border:hidden;background-color:transparent" data-toggle="tooltip" title="Download!">
<span type="submit" id="@item.ID;@item.AuthorID;Download" class="featurette-image img-fluid mx-auto glyphicon glyphicon-cloud-download" style="cursor:pointer;color:cornflowerblue;font-size: 2em;" data-toggle="tooltip" title="Download">
</span>
</button>
</form>
Контроллер:
public async Task<FileResult> DownloadFile(string fileName)
{
var path = Path.Combine(
Directory.GetCurrentDirectory(),
"wwwroot\\files\\", fileName);
var memory = new MemoryStream();
using (var stream = new FileStream(path, FileMode.Open))
{
await stream.CopyToAsync(memory);
}
memory.Position = 0;
return File(memory, MediaTypeNames.Application.Octet, Path.GetFileName(path));
}
ура!