Reputation: 221
I'm making a web app using ASP.NET MVC 4.
It lets people upload files.
I want to list all the files from a user with a link to open/download each file.
I have the virtual path to each file (e.g. :~/Folder/file.txt
), how can I generate the link with razor?
I tried with @Href
but it doesn't render anything, same thing with @Url.Content
.
I tried also without using razor but I don't think it's a good way...
Your help would be welcome! Thanks!
Upvotes: 2
Views: 9627
Reputation: 221
I don't know why @Href didn't work but it's the way to do it!
Here is a sample code:
@foreach (var s in Model)
{
<tr>
<td>@s.Id.ToString()</td>
<td>@s.Title</td>
<td>
@if (s.FilePath!= null && s.FilePath!= "")
{
<a href="@Href(s.FilePath)">link</a>
}
</td>
</tr>
}
Upvotes: 2