I try to get names of city with jquery ajax in mvc project. But get this error for me.
"NetworkError: 404 Not Found - http://localhost:1411/HomeController/GetCity/"
[HttpPost]
public ActionResult GetCity(int idCountry)
{
TravelEnterAdminTemplate.Models.LG.MyJsonResult myresult = new Models.LG.MyJsonResult();
try
{
var citystable = db.Cities.Where(p => p.CountryId == idCountry).ToList();
if (citystable != null)
{
myresult.Result = true;
myresult.obj = citystable;
}
else
{
myresult.Result = false;
myresult.message = "داده ای یافت نشد";
}
}
catch (Exception e)
{
errorlog.Error("DeleteShopping", "157", e.Source.ToString(), e.Message);
myresult.Result = false;
myresult.message = "خطا در بارگذاری اطلاعات";
}
return Json(myresult, JsonRequestBehavior.AllowGet);
}
The names of controller and method is true.
$(document).ready(function () {
country = $('#CountryId');
country.change(function() {
var id = country.val();
getCity(id);
}); //End country.change
function getCity(id) {
$.ajax({
type: "POST",
url: "/HomeController/GetCity/",
data: "{'idCountry':'" + id + "'}",
contentType: "application/json; charset=utf-8",
dataType: "json",
success: function (result) {
alert('hello');
var delay = function () {
AjaxSucceededSearch(result);
};
setTimeout(delay, 300); //remove this
},
error: AjaxFailedSearch()
});
} //End getCity
function AjaxSucceededSearch(result) {
$('#loading').remove();
if (result.d != null) {
for (var i = 0; i <= result.d.length; i++) {}
} else
if (result.d == false) {
alert("data is not found!!!");
}
}
function AjaxFailedSearch(jqXhr, textStates, errorThrown) {
alert(errorThrown + ' ' + textStates);
}
}); // End document ready


Home, notHomeControllerin the path:"/Home/GetCity/". Better yet use@Url.Action("GetCity", "Home")and also it's better to pass an object todatainstead of hacking together a string.controllerword fromurl: "/HomeController/GetCity/",