I have a folder with a .mp4 file that I want to be downloadable. I have the following code:
The PartialView:
@model List<string>
<div>
<div class="messeDiv">
<h2>Downloads</h2>
<br /><br />
@for (var i = 0; i < Model.Count; ++i)
{
<div>
@Model[i].ToString()
</div>
<div>
@Html.ActionLink("Download file", "DownloadFile", "FileDownload")
</div>
}
</div>
</div>
And the controller:
[Authorize]
public ActionResult DownloadFile()
{
string userMail = User.Identity.GetUserName();
string role = logic.GetUserRole(userMail);
if (!role.ToLower().Equals("model"))
{
return PartialView("_DenyAcces");
}
var dir = new DirectoryInfo(Server.MapPath("~/Videos/"));
FileInfo[] fileNames = dir.GetFiles("*.mp4");
List<string> items = new List<string>();
foreach (var file in fileNames)
{
items.Add(file.Name);
}
return PartialView("_AllFiles", items);
}
I want to make it so that if I click on the: @Html.ActionLink("Download file", "DownloadFile", "FileDownload")
link, then I should be asked if I want to download the file, just like what happens in a normal downloadable file. I am very new to asp.net mvc, and right now it is just out of control for me. I have tried finding different examples, and from those made the code I have so far. What more do I need to do to achieve what I want?
Right now when I click on the link I am taken to the URL: http://localhost:3918/FileDownload/DownloadFile
and nothing happens.