Is it possible to put ASp.NET tags in my javascript which is in a seperate script file. For example, I have the following
$.getJSON('/Postcode/GetAddressResults/' + $get('SearchPostcode').value, null, function(data) {
which I want to turn into but it does not like the ASP tags!
var action = '<%=Url.Content('~/Postcode/GetAddressResults/')%>' + $get('SearchPostcode').value $.getJSON(action, null, function(data) {
However this does not seem to work, what am I doing wrong?
Add to your master page(s) a meta tag to hold the value of the current applications path from the host (the bit the ~ represents).
In your Javascript create a function which will resolve a ~ prefixed path using the meta tag content.
Edit
Example as requested:-
Place this code in the head section your master pages:-
In your javascript include this function:-
Now your line of code is:-