I am trying to create a link so that users can download a file that is already on the server.
In my controller I have:
public ActionResult downloadFile(int id)
{
DataAccess da = new DataAccess();
PersonFile displayFile = new PersonFile();
displayFile = da.getPersonFileByID(id);
string mimeType = "application/pdf";
return File(displayFile.FileData, mimeType, displayFile.FileName);
}
Then in my view I have:
<th class="editAddLabel">
@Html.LabelFor(model => Model.PersonFile.FileName, "FileName")
*@Html.ActionLink("Download file", "downloadFile", "PersonController", Model.id, null )*
</th>
It's my first time doing something like this, but I feel like when the person clicks on the link, it should send the id of the model into the downloadFile method and then return the contents of the file. But when I click on the link, I get nothing. And when I set breakpoints on the downloadFile method, nothing happens either leading me to believe that the method is not even called. What could I be doing wrong?
Edit: I've also tried the following:
<input type="button" title="File" value="File" onclick="location.href='@Url.Action("downloadFile", "PersonController", new { id = Model.id })'; }" />
</th>
My error:
Server Error in '/' Application.
The resource cannot be found.
Description: HTTP 404. The resource you are looking for (or one of its dependencies) could have been removed, had its name changed, or is temporarily unavailable. Please review the following URL and make sure that it is spelled correctly.
Requested URL: /PersonController/downloadFile