šljaker šljaker - 1 year ago 176
jQuery Question

URL helper in JavaScript

I'm using jQuery Lightbox for my image gallery.

The URL for the button image is '


That works fine if my URL is '

If I use another route like '
' then URL to button images is incorrect.

Can I use
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 Source

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 = "<%= ... %>";

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download