I have ASP.NET MVC actions that return JSON data. My client uses jQuery's ajax
function to retrieve this data and display it on the screen. I use absolute paths to the controller actions in my JavaScript:
$.ajax({
url: '/Home/Load',
type: 'post',
dataType: 'json'
})
The problem is that in some environments, we'll add an extra virtual directory to the front, so the URL is actually /Path/To/App/Home/Load
. I am wondering whether there is a way to write my JavaScript so that it doesn't need updated each time I deploy. I could use relative URLs, like ../Home/Index
, but occasionally I move my JavaScript code around. Things get extra tricky when using MVC's bundler, too. It would be nice if the ~
character worked.