Using ASP.NET Razor Pages, I am trying download a file to the browser. From the Page(html), using a link like this works fine:
href="/DownloadableFiles/testB.csv" download="newname">Download Link
However, I want to initiate the download from the code-behind or ViewModel
so it can be dynamic as to what the filename is, I also need to inspect the file first, etc.
In ASP.NET MVC core, (not RazorPages) you can download a file in code using:
return File(memory, GetContentType(path), Path.GetFileName(path));
But return File
is not supported in Razor Pages.