views:

119

answers:

2

I have configured my default page to be say "abcd.aspx" and is under ~/View//abcd.aspx and I have my javascripts under ~/Contents/Scripts/.js

For some reason, only "../Content/Scripts/.js" works for including the js file on the page and "~/Contents/Scripts/.js" does not. This works only when i access the page with the full url: http:////controller/action. And since this is also the default page - accessing this via default page tries to load the scripts and the images will be broken as the relative path "../" - means that it would look under http://server/Contents/Scripts...

I thought using "~/" for the relative path should fix things, but as i mentioned it doesnt work for the full url and nor for the main default page.

Please let me know how i should be referring to the paths here.

Any help would be much appreciated.

Thanks!

+3  A: 

The easiest way would be to use "/Content/Scripts", the "~/" shortcut won't work in a standard script tag and using relative paths will break once the perceived path changes with different routes.

Andrew Van Slaars
+2  A: 

Using /Content/Scripts works, but has issues when you have installed your application under a virtual directory/application. If you are looking for the same type of behavior as in webforms, try using the Url helper:

<%=Url.Content("~/Content/Scripts/jquery-ui.js")%>"

Trevor de Koekkoek
I didn't know about that one. I'll have to start using that.
Andrew Van Slaars
Yep, that works like a charm!