Raju Fodse

Raju Fodse

  • 1.4k
  • 244
  • 29.4k

Implement Datatable in MVC using jQuery

May 28 2019 10:23 PM
I am trying to implement jquery datatable in mvc below is my controller code and View code But I get error. (I have client and Order table in which Client is master and Order is detail table).
Below is my controller code
  1. public ActionResult IndexSS()    
  2.         {    
  3.             return View();    
  4.         }    
  5.     
  6.         public ActionResult LoadData()    
  7.         {    
  8.             using (LPDBContext db = new LPDBContext())    
  9.             {    
  10.                 var data = db.ValueAddLists.OrderBy(p => p.RefName).ToList();    
  11.                 return Json(new { data = data }, JsonRequestBehavior.AllowGet);    
  12.             }    
  13.     
  14.     
  15.         }    
 and below is My IndexSS code
  1. @{    
  2.     
  3.     ViewBag.Title = "Index";    
  4.     //Layout = null;    
  5. }    
  6. <div class="EasyViewHeader">    
  7.     <h1>ServerSide List</h1>    
  8. </div>    
  9. <div class="EasyViewDiv">    
  10.     <div style="width:90%">    
  11.         <table style="font-size:20px" class="table table-bordered table-hover" id="myTable">    
  12.             <thead>    
  13.                 <tr>    
  14.                     <th>Order ID</th>    
  15.                     <th>Order Size</th>    
  16.                     <th>Specification</th>    
  17.                     <th>QTY</th>    
  18.                     <th>MTRS</th>    
  19.                     <th>STATUS</th>    
  20.                 </tr>    
  21.             </thead>    
  22.     
  23.         </table>    
  24.     </div>    
  25. </div>    
  26. <meta name="viewport" content="width=device-width" />    
  27. <link href="~/Content/CustomStyle.css" rel="stylesheet" type="text/css" />    
  28. <link href="~/Content/jquery-ui.css" rel="stylesheet" />    
  29. <script src="~/Scripts/jquery-ui-1.12.1.js"></script>    
  30. <script src="~/Scripts/jquery-3.3.1.js"></script>    
  31. <link href="~/Content/bootstrap.min.css" rel="stylesheet" />    
  32. <link href="~/DatatableBS/datatables.min.css" rel="stylesheet" />    
  33. <script src="~/DatatableBS/datatables.min.js"></script>    
  34. <link href="~/Content/TablesStyle.css" rel="stylesheet" />    
  35.     
  36.     
  37.   
  38. @section Scripts{    
  39.         
  40.     <script>    
  41.     $(document).ready(function () {    
  42.         $("#myTable").DataTable({    
  43.             //"processing": true, // for show progress bar    
  44.             //"serverSide": true, // for process server side    
  45.             //"filter": false, // this is for disable filter (search box)    
  46.             //"orderMulti": false, // for disable multiple column at once    
  47.             "ajax": {    
  48.                 "url": "/Orders/LoadData",    
  49.                 "type": "GET",    
  50.                 "datatype": "json"    
  51.             },    
  52.             "columns": [    
  53.                     { "data": "OrderID", "name": "OrderID", "autoWidth": true },    
  54.                     { "data": "ORDSZ", "name": "ORDSZ", "autoWidth": true },    
  55.                     { "data": "PISPEC", "name": "PISPEC", "autoWidth": true },    
  56.                     { "data": "ORDQTY", "name": "ORDQTY", "autoWidth": true },    
  57.                     { "data": "ORDMTR", "name": "ORDMTR", "autoWidth": true },    
  58.                     { "data": "Status", "name": "Status", "autoWidth": true }    
  59.                        
  60.             ]    
  61.         });    
  62.     });    
  63.     </script>    
  64.     
  65. }    
 
But I get following error while running application
DataTables warning: table id=myTable - Ajax error. For more information about this error, please see http://datatables.net/tn/7.
 
and same code running smoothly on single table which not having any forign key references. How can i RETRIVE data in datatable 

Attachment: Desktop.rar

Answers (1)