2

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!

18
  • you are saving files in a folder??? Commented Aug 13, 2014 at 9:16
  • @Exception, where do you usually save yours? :) Commented Aug 13, 2014 at 9:17
  • @AndreiV...database.... Commented Aug 13, 2014 at 9:17
  • Are you referencing the file hardcoded in your project? Commented Aug 13, 2014 at 9:18
  • 2
    @Exception, You save files to a database!?!?! Well that's expensive... Why not something like Azure Storage? Of just a directory? Commented Aug 13, 2014 at 9:19

1 Answer 1

2

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>
}
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.