Reputation: 8684
I have a controller that returns a list of files in a directory using DirectoryInfo.GetFiles()
public ActionResult Index()
{
DirectoryInfo vidDir = null;
FileInfo[] files = null;
string dirPath = @"/Content/Videos";
vidDir = new DirectoryInfo(Server.MapPath(dirPath));
files = vidDir.GetFiles();
return View(files);
}
In my view I enumerate the files with the following code:
<ul> @foreach (var file in Model) {
<li>
@file
</li>
}
</ul>
What I would like to do is foreach (var file in Model) { create a hyperlink to file }
I was able to hard code a link using @html.actionlink
@Html.ActionLink("Test Link", "file1.txt", "Content/Videos");
When I put in @file for the first two parameters, I get an error that says:
'System.Web.Mvc.HtmlHelper' has no applicable method named 'ActionLink' but appears to have an extension method by that name"
How can I use @html.Actionlink to create a hyperlink to all the files passed into the view?
Upvotes: 1
Views: 3160
Reputation: 1681
I am using below code and it works just fine
foreach (var menuName in menuNames)
{
@Html.ActionLink(menuName.Value, menuName.ActionName, menuName.ControllerName)
}
(I am using this in MVC 4)
Upvotes: 0
Reputation: 31250
These seem to be a direct link to those files. If so
<a href="@Url.Content(string.Concat("Content/Videos/", @file))">@file</a>
Upvotes: 3