Hi BugHunter,
Check this example. Now please take its reference and correct your code.
Controller
public class HomeController : Controller
{
// GET: /Home/
public ActionResult Index()
{
return View();
}
[HttpPost]
public FileResult Index(string name)
{
string file = System.IO.Path.Combine(Server.MapPath("Files"), name);
if (System.IO.File.Exists(file))
{
byte[] bytes = System.IO.File.ReadAllBytes(file);
return File(bytes, System.Net.Mime.MediaTypeNames.Application.Octet, name);
}
return null;
}
}
View
<body>
<div>
<%using (Html.BeginForm()) {%>
<%:Html.TextBox("name") %>
<%:Html.ActionLink("Download", "Index", "Home", new { @id = "btnDownload" })%>
<% } %>
</div>
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.8.3/jquery.min.js"></script>
<script type="text/javascript">
$(function () {
$("#btnDownload").click(function () {
document.forms[0].submit();
return false;
});
});
</script>
</body>