I have the following situation.
I developed my first MVC Asp.Net application. it runs on my server at the following adress
http://localhost:59441/
I had this kind issue on MVC 5 using JQuery, so I went to this solution that gets rid of the problem when you are in Localhost, and in any Navigator even when you're deploying app in a subfolder.
var pathname = window.location.pathname;
var VirtualDirectory;
if (pathname.indexOf("localhost") >= 0 && pathname.indexOf(":") >= 0) {
VirtualDirectory = "";
}
else {
if ((pathname.lastIndexOf('/')) === pathname.length + 1) {
VirtualDirectory = pathname.substring(pathname.indexOf('/'), pathname.lastIndexOf('/'));
} else {
VirtualDirectory = pathname;
}
}
And then in any ajax call :
$.post(VirtualDirectory + "/Controller/Action", { data: data}, "html")
.done(function (result) {
//some code
});