I’m encountering an issue where my AJAX call isn’t reaching the controller method in my ASP.NET Core application. Despite setting up the AJAX call and controller method, I’m receiving a 404 error. Here’s my controller method and JavaScript function:
[HttpPost]
public async Task<ActionResult> GetCityConfigurations(DSParamsDto dSParams)
{
// Your controller logic here
var citys = await cityService.Getcitys(dataTableParams);
return Json(new JqueyDataTableResponseModel<cityDto>
{
draw = dataTableParams.Draw,
recordsTotal = citys.Total,
recordsFiltered = citys.Total,
data = citys.Items
});
}
function GetcitySapConfigurations() {
var token = $('input[name="__RequestVerificationToken"]').val();
citySapConfig = $("#tblcitySapConfiguration").DataTable({
"processing": true,
"serverSide": true,
"ajax": {
"url": 'GetCityConfigurations/',
"type": "POST",
"datatype": "json",
"headers": { "XSRF-TOKEN": token },
"error": handleAjaxErrorLoc
},
"columns": [
{
"data": "cityId"
},
{ "data": "cityName" }
]
});
}
I’ve confirmed that the URL in the AJAX call (‘GetCityConfigurations/’) is correct, and I’ve included the necessary anti-forgery token. However, the request doesn’t seem to reach the controller action. Any insights into what might be causing this issue would be greatly appreciated. Thank you!
akhilesh jain is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.