I have an Asp.net core MVC project in visual studio. I have added a folder called Download to the project and added the file "ReadMe.txt" into that folder. I'm trying to enable the user to download the file. In my view I have:
@Html.ActionLink("Readme.txt", "ReadMe", "Download")
This calls the ReadMe action inside the DownloadController. However, I have been struggling for the past hour to write the action method to return the file.
I think something like this should do it but the IDE does not recognise Server and I cannot find an import to resolve it. I've tried using System.Web and it does not work.
public FileResult ReadMe()
{
string filename = "ReadMe_2.1.txt";
string serverpath = Server.MapPath("~/Download/");
string filepath = serverpath + filename;
return File(filepath, System.Net.Mime.MediaTypeNames.Application.Octet, filename);
}
Any suggestions?