šljaker šljaker - 2 months ago 28
jQuery Question

URL helper in JavaScript

I'm using jQuery Lightbox for my image gallery.

The URL for the button image is '

../../Content/Lightbox/lightbox-btn-next.gif
'

That works fine if my URL is '
localhost/Something1/Somtehing2
'

If I use another route like '
localhost/Something1/Something2/Something3
' then URL to button images is incorrect.

Can I use
Url.Action()
inside .js files?

This is how I call .js files:

<script type="text/javascript" src="<%= Url.Content("~/Scripts/jquery.lightbox-0.5.js") %>"></script>

Answer

You can't use Url.Action() inside .js files. But you can define global variable and use it in you js file.

<script type="text/javascript">

    var imageUrl = "<%= ... %>";

</script>