How do you make a call to MVC Web API from Javascript for Datatables?????
How do you make a call to MVC Web API from Javascript for Datatables?????
JArmbruster
Posts: 5Questions: 1Answers: 0
JavaScript call:
$('#example').DataTable( {
"ajax": { url: "/api/PatientData/SearchPatientRecord",
"data": { 'patientName': "Smith", 'insuranceNumber': "99" },
"type": "POST"
},
"serverSide":true,
"columns": [
{ "data": "comp_name" },
{ "data": "addr_Address1" },
{ "data": "addr_State" },
{ "data": "pers_FirstName" },
{ "data": "pers_LastName" },
{ "data": "pers_Gender" }
]
} );
C# Web API method:
[HttpPost]
[Route("SearchPatientRecord")]
public string SearchPatientRecord(HttpRequestMessage request, [FromBody]List<string> value)
{
//PatientInsuranceRecords pRcrds = new PatientInsuranceRecords();
//return JsonConvert.SerializeObject(pRcrds.SearchPatientRecordsWM(patientName, insuranceNumber));
return "Test";
}
The call is received, but I cam not see the parameters that are passed, including the parameters passed by DataTables.
Help?
Jeff
This question has an accepted answers - jump to answer
This discussion has been closed.
Answers
Do you really need that? Are you working with tens of thousands of records or more? If you are, you'd need to implement server-side processing at the server.
Allan
Allan,
I actually have over 100,000 records (patients) for a medical company.
The web page allows user to search and edit patient records. Table shows search results.
So user enters patient name or insurance number. If name, web page needs to show list of found names.
So the question is, what are the steps to using DataTables to display the info?
I assume this:
Call function:
JavaScript code:
But DataTables passes a long list of parameters.
Web API code:
But I can't seem to grab the parameters that are being passed by DataTables???????
Help????
Jeff
Server-side processing it is then .
Yes - those parameters tell the server what data DataTables wants to display (number of records in a page, page start, any filtering, etc).
Exactly how you access that information is really a server-side issue. It looks like you have the information from the POST request in the
value
property, and you'd need to take the data from there - the Microsoft .NET documentation would be where to find out how to do that. Possibly simplyvalue["draw"]
, etc, but I'm honestly not sure as I'm not familiar withFromBody
.There is another option - you could try using Editor's .NET implementation, which does fully support server-side processing. Although Editor is paid for software, you don't need a license if you are only going to use the server-side library and not the client-side javascript.
Allan