Does this URL render from a Razor file?

curiouswebster
curiouswebster used Ask the Experts™
on
<img src="../Content/images/global/PHOTO.gif" />

I am worried about the ../ in the front. I have gotten used to using :

~/Content/...

for the root directory. Usually the .. prefix means one folder up.

Please explain this.


Thanks,
Robert

Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
".." does mean one folder up. So, the img path is given relative to the URL of the document where the image path is rendered. If that IMG tag appeared on a page at:

    www.foo.com/mySite/someFolder/thisPage.html

... then the image path would resolve to:

    www.foo.com/mySite/Content/images/global/PHOTO.gif

When "~" is used in a URL on a server control (note: it MUST BE on a server control like <asp:Image>, not just any plain vanilla HTML IMG tag), the server will replace the "~" with what it thinks the site's root URL is when it transforms the server control into HTML. So, <img src="~/Content/images/global/PHOTO.gif" /> will probably never work, since the IMG element is not a server control, but rather an HTML tag that does not require any translation by the server.
curiouswebsterSoftware Engineer

Author

Commented:
Which is why you meed @Url.Content()
src="@Url.Content("~/Scripts/js/libs/jquery.ui.core.js")"

right?

Exactly.
curiouswebsterSoftware Engineer

Author

Commented:
Thanks.

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial