So I’ve got some Javascript in a seperare js file (jquerySliderMenu.js)
to resolve the url of an image i do this:
var imgUrl = $Url.resolve(“~/Assets/Javascript/Img”);
works find in dev, (iis 6)
but on prod(iis 7.5) , it resolves to
https://XXXX.org/Home.mvc.aspx/~/Assets/Javascript/Img/right.gif
instead of
https://XXXX.org/Assets/Javascript/Img/right.gif
Which causes an error.
I remember the IT guys had to add the .MVC. stuff but i can’t rememebr why or how they did it.
Is there a better way to resolve the issue that will work with the settings that add the .mvc.aspx to everything? (And please, what is that setting?)
Thansk,
Eric-
You should not be trying to resolve any urls in ytour javascript files. You should use url helpers to generate them in the HTML. Javascript will then unobtrusively read and use them.
You could use HTML5 data-* attributes, the same way unobtrusive AJAX and client side validation works. So for example let’s suppose that you have the following element in your DOM
and then in your javascript:
or in the case you are for example unobtrusively AJAXifying an anchor or a form, you could directly fetch the
hreforactionattributes on the corresponding DOM elements which would of course have been generated with Url/Html helpers and thus ensuring proper urls respecting routes.