Possible solution - specify the form method and controller name:
@using (Html.BeginForm("DownloadFile", "Controller", FormMethod.Get))
{ <input type="submit" value="Download" /> }
or try using an action link instead of a form:
@Html.ActionLink("Download", "DownloadFile", "Controller")
or try providing a direct url to the file:
<a href="~/App_Data/MyFile.pdf">Download</>
This is not a good practice due to security concerns, but you can try ... Alternatively, you can bind the file location to some helper method @Html:
public static class HtmlExtensions {
private const string FDir_AppData = "~/App_Data/";
public static MvcHtmlString File(this HtmlHelper helper, string name){
return MvcHtmlString.Create(Path.Combine(FDir_AppData, name));
}
}
And in the view:
<a href="@Html.File("MyFile.pdf")">Download</>
source
share