L A

L A

  • NA
  • 170
  • 171.2k

jQuery DataTables - Can't bind data

Mar 31 2017 3:51 PM
Hi all,
 
My application (ASP.NET MCV) refrences a Webservice to GET data & display using DataTables jQuery (https://datatables.net/).
  •  Created ajax function to call Controller/ Action.
  1. <script src="~/Scripts/jquery.js"></script>  
  2. <script src="~/Scripts/DataTables/jquery.dataTables.js"></script>  
  3. <script src="https://cdn.datatables.net/v/dt/dt-1.10.13/datatables.min.js"></script>  
  4.   
  5. <script type="text/javascript">  
  6.     $(document).ready(function () {  
  7.         $.ajax({  
  8.             type: 'POST',  
  9.             url: '@Url.Action("GetDetailsFromService", "GetProductData")',  
  10.             dataType: "json",  
  11.             success: function (DBdata) { 
  12.                 alert(DBdata); //Data To Display in Alertbox
  13.                 $('#productDataTable').DataTable({  
  14.                     data: DBdata,  
  15.                     columns: [  
  16.                         { "data""ProductName" },  
  17.                         { "data""SupplerName" },  
  18.                         { "data""CategoryName" }]  
  19.                 });  
  20.             }  
  21.         });  
  22.     });  
  23. </script> 
  • Consumed Webservice data to show.
  1.     [HttpPost]  
  2.     public ActionResult GetDetailsFromService()  
  3.     {  
  4.         ProductDetails.GetDetailsService service = new ProductDetails.GetDetailsService();  
  5.             JavaScriptSerializer json = new JavaScriptSerializer();  
  6.             return Json(json.Serialize(service.GetProductData()), JsonRequestBehavior.AllowGet);        
  7.    } 
  • JSON data shown in alert box from webservice.


  • Can't bind data to jQuery DataTable


Please help me out, to figure whats the problem.

Answers (2)