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 :
- @* Load datatable css @ @*"//cdn.datatables.net/1.10.9/css/jquery.dataTables.min.css" rel="stylesheet" />*@ "~/Content/DataTable/jquery.dataTables.min.css" rel="stylesheet" /> @ Load datatable js *@ @section Scripts{
- @**@
- }
Controller Code
- [HttpPost]
- public ActionResult LoadData()
- {
- //Get parameters
- // get Start (paging start index) and length (page size for paging)
- string Search = Request.Form.GetValues("search[value]")[0];
- var draw = Request.Form.GetValues("draw").FirstOrDefault();
- var start = Request.Form.GetValues("start").FirstOrDefault();
- var length = Request.Form.GetValues("length").FirstOrDefault();
- //Get Sort columns value
- var sortColumn = Request.Form.GetValues("columns[" + Request.Form.GetValues("order[0][column]").FirstOrDefault() + "][name]").FirstOrDefault();
- var sortColumnDir = Request.Form.GetValues("order[0][dir]").FirstOrDefault();
- //find search columns info
- int pageSize = length != null ? Convert.ToInt32(length) : 0;
- int skip = start != null ? Convert.ToInt32(start) : 0;
- int totalRecords = 0;
- using (CountryEntities dc = new CountryEntities())
- {
- dc.Configuration.LazyLoadingEnabled = false;
- // var v = (from a in dc.tblCountry select a);
- var ad = (from dm in db.tblCountry
- select new
- {
- dm.CountryName,
- dm.CountryID,
- }).ToList();
- //Sorting
- var v = (from a in dc.tblCountry orderby a.countryID select a).AsQueryable();
- // SEARCHING...
- if (!string.IsNullOrEmpty(Search))
- {
- v = v.Where(a => a.CountryName.Contains(Search.ToLower()));
- }
- //Sorting
- if (sortColumn!="")
- {
- if (!(string.IsNullOrEmpty(sortColumn) && string.IsNullOrEmpty(sortColumnDir)))
- {
- v = v.OrderBy(sortColumn + " " + sortColumnDir);
- }
- }
- totalRecords = v.Count();
- var data = v.Skip(skip).Take(pageSize).ToList();
- return Json(new { draw = draw, recordsFiltered = totalRecords, recordsTotal = totalRecords, data = data }, JsonRequestBehavior.AllowGet);
- }
- }
Sachin SinghPosted Dec 14, 2020, 6:32 AM
Mageshwaran RPosted Dec 14, 2020, 6:13 AM