Let say I have a web application :
http://www.mymvcsite.com/MyVirtualDirectory/Controller/Action
In my view I have a <a href="/FolderA/myfile.pdf">. Problem is the entire Html is coming from from a database! Aha! You thought this was as easy as @Url.Content()… well that doesn’t work cause the html is dynamic in fact I have no idea that there is even link element in the markup I’m blindly outputting it to the view.
So what do I need to put in the href in order for it to resolve the Url properly.
Ie. “myfile.pdf” is located at…
http://www.mymvcsite.com/MyVirtualDirectory/FolderA/myfile.pdf
BUT for some reason in the browser the url ends up being
“www.mymvcsite.com/FolderA/myfile.pdf”
Note that the “MyVirtualDirectory” is missing! I even tried adding a “~” to the Url but that doesn’t work either.
Thanks!
You need to store the relative url in a hidden field:
All links should be relative to the root of the site and have a common class name:
Then when you load it into the page you do:
Set the href property on each one returned to include the first part of your url. I would store the first part of your url in a hidden field.