MVC Javascript error

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.



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:


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.

Need Your Help