Asht T

Asht T

  • 1.3k
  • 333
  • 11k

Jquery Datatatable MVC not working After publish IIS

Dec 14 2020 4:35 AM
MVC Application
 
Jquery datatable work fine in MVC Application but after publish and host on IIS then Jquery datatable not working.
 
My View Binding Code :
  1. @* Load datatable css @ @*<link href="//cdn.datatables.net/1.10.9/css/jquery.dataTables.min.css" rel="stylesheet" />*@ <link href="~/Content/DataTable/jquery.dataTables.min.css" rel="stylesheet" /> @ Load datatable js *@ @section Scripts{  
  2. @*<script src="//cdn.datatables.net/1.10.9/js/jquery.dataTables.min.js"></script>*@  
  3. <script src="~/Scripts/DataTable/jquery.dataTables.min.js"></script>  
  4. <script>  
  5. $(document).ready(function () {  
  6. //jQuery DataTables initialization  
  7. $('#myTable').DataTable({  
  8. "processing"true// for show processing bar  
  9. "serverSide"true// for process on server side  
  10. "orderMulti"false// for disable multi column order  
  11.   
  12. "filter"true,  
  13. //"dom": '<"top"i>rt<"bottom"lp><"clear">',  
  14. "ajax": {  
  15. "url""/CountryMaster/LoadData",  
  16. "type""POST",  
  17. "datatype""json"  
  18. },  
  19. "columns": [  
  20. "data""CountryName""name""CountryName""autoWidth"true }, //index 0  
  21. {  
  22. "data""CountryId""width""50px""render"function (data) {  
  23. return '<a class="popup" href="/CountryMaster/Edit/' + data + '">Edit</a>';  
  24. }  
  25. }  
  26. ]  
  27. });  
  28. });  
  29. </script>  
  30. }  
Controller Code
  1. [HttpPost]  
  2. public ActionResult LoadData()  
  3. {  
  4. //Get parameters  
  5. // get Start (paging start index) and length (page size for paging)  
  6. string Search = Request.Form.GetValues("search[value]")[0];  
  7. var draw = Request.Form.GetValues("draw").FirstOrDefault();  
  8. var start = Request.Form.GetValues("start").FirstOrDefault();  
  9. var length = Request.Form.GetValues("length").FirstOrDefault();  
  10. //Get Sort columns value  
  11. var sortColumn = Request.Form.GetValues("columns[" + Request.Form.GetValues("order[0][column]").FirstOrDefault() + "][name]").FirstOrDefault();  
  12. var sortColumnDir = Request.Form.GetValues("order[0][dir]").FirstOrDefault();  
  13. //find search columns info  
  14. int pageSize = length != null ? Convert.ToInt32(length) : 0;  
  15. int skip = start != null ? Convert.ToInt32(start) : 0;  
  16. int totalRecords = 0;  
  17. using (CountryEntities dc = new CountryEntities())  
  18. {  
  19. dc.Configuration.LazyLoadingEnabled = false;  
  20. // var v = (from a in dc.tblCountry select a);  
  21. var ad = (from dm in db.tblCountry  
  22. select new  
  23. {  
  24. dm.CountryName,  
  25. dm.CountryID,  
  26. }).ToList();  
  27. //Sorting  
  28. var v = (from a in dc.tblCountry orderby a.countryID select a).AsQueryable();  
  29. // SEARCHING...  
  30. if (!string.IsNullOrEmpty(Search))  
  31. {  
  32. v = v.Where(a => a.CountryName.Contains(Search.ToLower()));  
  33. }  
  34. //Sorting  
  35. if (sortColumn!="")  
  36. {  
  37. if (!(string.IsNullOrEmpty(sortColumn) && string.IsNullOrEmpty(sortColumnDir)))  
  38. {  
  39. v = v.OrderBy(sortColumn + " " + sortColumnDir);  
  40. }  
  41. }  
  42. totalRecords = v.Count();  
  43. var data = v.Skip(skip).Take(pageSize).ToList();  
  44. return Json(new { draw = draw, recordsFiltered = totalRecords, recordsTotal = totalRecords, data = data }, JsonRequestBehavior.AllowGet);  
  45. }  
  46. }  

Answers (2)