0

I'm building a mvc3 application which uses a SQL Server Database with a table named Field. this table has many columns.one of it's columns is File9Terme with string value and store a PDF file path that stores in a folder named BOOKS. I build a upload file for this. but now I want to build a download link for each PDF file. here is my code:

 [HttpPost]
 public FileResult Download(int id)
 {
    var document = db.Fields.First(f => f.FieldId == id);
    var filename = document.File9Terme;
    return File(filename, document.GetType().ToString());
 }    

and here is my Index view:

<td>
<%= Html.ActionLink("Download", "Download", "FieldController", new { id=item.FieldId })%>
</td>

where is the problem? thanks for help.

ReZa
  • 1
  • 1
  • possible duplicate of [Returning a file to View/Download in MVC](http://stackoverflow.com/questions/5826649/returning-a-file-to-view-download-in-mvc) – Liam Apr 09 '14 at 15:59

1 Answers1

0

If you are using a link, it will send a GET request. So remove [HttpPost].

Secondly, if the Download action method is in the FieldController, simply provide "Field" in your ActionLink and not "FieldController"

<td>
<%= Html.ActionLink("Download", "Download", "Field", new { id=item.FieldId })%>
</td>
Andy T
  • 10,223
  • 5
  • 53
  • 95