MVC Javascript error

I configured my default page to 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 to include the js file in the page, while "~ / Contents / Scripts / .js" does not. This only works when accessing the page with the full url: http: // // controller / action. And since this is also the default page - accessing it through the default page tries to load scripts and the images will be broken, since the "../" relative path means it will look under http: // server / Contents / Scripts . ..

I thought using "~ /" for the relative path should fix the situation, but as I mentioned, it doesn't work for the full url, nor for the default home page.

Please let me know how I should link to paths here.

Any help would be much appreciated.

Thank!

+1


source to share


2 answers


Using / Content / Scripts works but has problems when you installed the app under the virtual directory / app. If you're looking for the same type of behavior found in web forms, try using the Url helper:



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

+2


source


The easiest way is to use "/ Content / Scripts", the shortcut "~ /" will not work in a standard script tag, and using relative paths will break when the perceived path changes with different routes.



+3


source







All Articles