Hi Team
I am returning an empty record list on my dataTable, what could be an issue? Is the issue on my calling of dbContext not correcttly? Please help me mates as i am returning an empty record list on UI. Here is my logic below for this reason.
- [HttpPost]
- public ActionResult GetList() {
-
- int start = Convert.ToInt32(Request["start"]);
- int length = Convert.ToInt32(Request["length"]);
- string searchValue = Request["search[value]"];
- string sortColumnName = Request["columns[" + Request["order[0][column]"] + "][name]"];
- string sortDirection = Request["order[0][dir]"];
- using(eNtsaOnlineRegistrationDBContext db = new eNtsaOnlineRegistrationDBContext()) {
- IQueryable < TblEventsManagements > empList = db.TblEventsManagements;
- int totalrows = empList.Count();
- int totalrowsafterfiltering = totalrows;
-
- if (!string.IsNullOrEmpty(searchValue)) {
- empList = empList.Where(x => x.TrainingType.Contains(searchValue) || x.TrainingDescription.Contains(searchValue) || x.Price.ToString().Contains(searchValue.ToLower()) ||
- x.Venue.Contains(searchValue) || x.Facilitator.Contains(searchValue) || x.WhoAttend.Contains(searchValue) || x.Rsvp.Contains(searchValue));
- totalrowsafterfiltering = empList.Count();
- }
- empList = empList.OrderBy(sortColumnName + " " + sortDirection).Skip(start).Take(length);
-
- return Json(new {
- data = empList.ToList(), draw = Request["draw"], recordsTotal = totalrows, recordsFiltered = totalrowsafterfiltering
- }, JsonRequestBehavior.AllowGet);
- }
- }
- <script>
- $(document).ready(function () {
- $("#EventsManagementsTable").DataTable({
- "ajax": {
- "url": "/Dashboard/GetList",
- "type": "POST",
- "datatype":"json"
- },
- "columns": [
- {"data": "TrainingType", "name": "TrainingType"},
- { "data": "TrainingDescription", "name": "TrainingDescription" },
- { "data": "Price", "name": "Price" },
- { "data": "Venue", "name": "Venue" },
- { "data": "Facilitator", "name": "Facilitator" },
- { "data": "WhoAttend", "name": "WhoAttend" },
- {"data": "RSVP", "name": "RSVP"},
- ],
-
- "serverSide": "true",
- "order":[0,"asc"],
- "processing": "true",
- "language": {
- "processing":"processing... please wait"
- }
- });
- });
- </script>