I have an ASP.NET MVC web application running from http://localhost/myappname
. From jQuery, I make jQuery $.ajax() calls to return partial views based on some
I was able to accomplish this with straight JavaScript using window.location.pathname
. See the following example:
function loadMyPartialView() {
$.ajax({
type: 'GET',
url: window.location.pathname + 'Home/GetNavigationTreePV/',
success: function (data) { onSuccess(data); },
error: function (errorData) { onError(errorData); }
});
return true;
}
I think in your MVC View page you need @Url.Action
function loadMyPartialView() {
$.ajax({
type: 'GET',
url: '@Url.Action("GetNavigationTreePV", "Home")',
success: function (data) { onSuccess(data); },
error: function (errorData) { onError(errorData); }
});
return true;
}
Alternatively you can use @Url.Content
function loadMyPartialView() {
$.ajax({
type: 'GET',
url: '@Url.Content("~/home/GetNavigationTreePV")',
success: function (data) { onSuccess(data); },
error: function (errorData) { onError(errorData); }
});
return true;
}
If this is in a .js file, you can pass in the Url like
loadMyPartialView('@Url.Action("GetNavigationTreePV", "Home")')