Ajax post method does not fire action controller in ASP .NET CORE 3

Ajax post method does not fire action controller in ASP .NET CORE 3

IcognitoShiroIcognitoShiro Posts: 2Questions: 0Answers: 0

Hi everyone,
I'm trying to initialise a DataTable after button click and fill it with some Data from database, but the ajax method couldn't find the requested Url and showing me this error on console : "jquery.min.js:2 POST https://localhost:44311/FillIssueTable 404"
and an alert message showing this "DataTables warning: table id=IssueDatatable - Cannot reinitialise DataTable. For more information about this error, please see http://datatables.net/tn/3".

Notice That :
i have no pbm with button function.
i tried to to put button type to "submit" and my asp-actiont to my controlller action "FillIssueTable" : my action controller actually fired up and i got raw data on my screen.
i tried many ways to to pass the URL
* https://localhost:44311/Home/FillIssueTable"
* https://localhost:44311/FillIssueTable"
* '@Url.Action("FillIssueTable~~~~","Home")'

Help please and thank you
Shiro

here is my code:
Index.cshtml
'''

IssueCode IssueName IssuePriority TakeOnDuration

'''

---Controller

'''[HttpPost]
public async Task<IActionResult> FillIssueTable(SLAGeminiModel model)
{
string indicator = model.IndicatorCode;
return Json( await GenericProvider<SlaExport>.Instance.ExecuteDataSetStoredProcedure("GetDataFor"+ indicator, cmd =>
{
cmd.Parameters.Add(new SqlParameter() { ParameterName = "@ProjectId", Value = model.ProjectId });
cmd.Parameters.Add(new SqlParameter() { ParameterName = "@StartDate", Value = model.StartDate});
cmd.Parameters.Add(new SqlParameter() { ParameterName = "@EndDate", Value = model.EndDate });
if (indicator == "BackLog")
cmd.Parameters.Add(new SqlParameter() { ParameterName = "@Date", Value = model.Date });
}, null, true));
}'''

---Javascript

'''function InitIssueTable() {
$('#BtnChart').click(function () {
alert("BlaBla")
$('#IssueDatatable').DataTable({
"processing": true,
"responsive": true,
"paging": true,
"searching": true,
"info": false,
"ajax": {
"url": '/FillIssueTable',
"type": "POST",
"datasrc": "",
"error": function () {
}
},
"columns": [
{ "data": "issueCode", "name": "IssueCode" },
{ "data": "issueName", "name": "IssueName" },
{ "data": "issuePriority", "name": "IssuePriority" },
{ "data": "takeOnDuration", "name": "TakeOnDuration" },
],
"bjqueryui": true,
"order": [[0, "desc"]]
});

});

}'''

Replies

  • kthorngrenkthorngren Posts: 21,166Questions: 26Answers: 4,921

    POST https://localhost:44311/FillIssueTable 404

    This is a response from your web server. You will need to look at the logs of the web server to determine why it is returning a 404 error. The error is not generated by Datatables.

    DataTables warning: table id=IssueDatatable - Cannot reinitialise DataTable. For more information about this error, please see http://datatables.net/tn/3

    Did you follow the troubleshooting steps provided in the link? Datatables will only initialize once. You need to use one of the destroy options provided in the link to reinitialize Datatables.

    Kevin

This discussion has been closed.