Here's the case.
- I am using ajax call in datatable js to bind json data in my table.
- Right now I am using directly json file for databinding.
- Now I want to access the data from my db for which I have written a method inside my controller which returns json value.
But I am not able to call this method like I was calling my json file in ajax. Kindly suggest the solution.
Below are the code sample
var table = $('#example').DataTable({ "ajax": "/content/data/dataList.json", //here I want the url of my method. "bDestroy": true, "iDisplayLength": 15, "columns": [ { "class": 'details-control', "orderable": false, //"data": null, "defaultContent": '' }, { "data": "name" }, ], "order": [[1, 'asc']], "fnDrawCallback": function (oSettings) { runAllCharts(); } });
And my method id :
//Controller Name AppDetail
public string getData(string ddlid)
{
DataTable ddl = new DataTable();
string query = string.Empty;
if (ddlid == "O1")
{
query = "SELECT for O1";
}
else if (ddlid == "O2")
{
query = "SELECT for O2";
}
con.Open();
MySqlDataAdapter da = new MySqlDataAdapter(query, con);
da.Fill(ddl);
con.Close();
System.Web.Script.Serialization.JavaScriptSerializer jSearializer = new System.Web.Script.Serialization.JavaScriptSerializer();
return jSearializer.Serialize(ddl);
}
And here is the json data sample
{
"data": [
{
"name": "Aladdin"
}
]
}
Kindly Help.