введите описание изображения здесь введите описание изображения здесь
У меня есть dataTable, но он не возвращает никаких полей записи из базы данных, имеется небольшая выборка данных доступно создано. Я использую обработку на стороне сервера, чтобы сделать это, так или иначе моя логика c не работает, и мне нужна некоторая помощь для этого, чтобы добиться этого лучше Что это приложение до сих пор возвращает пустой список записей без доступных данных, что мне не хватает именно здесь ниже logi c, чтобы получить результаты обратно?
[HttpPost]
public ActionResult GetList()
{
//Server side Parameter.
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]"];
List<TblEventsManagements> empList = new List<TblEventsManagements>();
using (eNtsaOnlineRegistrationDBContext db = new eNtsaOnlineRegistrationDBContext())
{
empList = db.TblEventsManagements.ToList<TblEventsManagements>();
int totalrows = empList.Count();
if (!string.IsNullOrEmpty(searchValue))
{
empList = empList.Where(x => x.TrainingType.ToLower().Contains(searchValue.ToLower()) || x.TrainingDescription.ToLower().Contains(searchValue.ToLower()) || x.Price.ToString().Contains(searchValue.ToLower())
|| x.Venue.ToLower().Contains(searchValue.ToLower()) || x.Facilitator.ToLower().Contains(searchValue.ToLower()) || x.WhoAttend.ToLower().Contains(searchValue.ToLower()) || x.Rsvp.ToLower().Contains(searchValue.ToLower())).ToList<TblEventsManagements>();
}
int totalrowsafterfiltering = empList.Count;
empList = empList.OrderBy(sortColumnName + " " + sortDirection).ToList<TblEventsManagements>();
empList = empList.Skip(start).Take(length).ToList<TblEventsManagements>();
return Json(new { data = empList, draw = Request["draw"], recordsTotal = totalrows, recordsFiltered = totalrowsafterfiltering }, JsonRequestBehavior.AllowGet);
}
}
// Redo function call still not getting any results. The table has data with 3 records available of data.
[HttpPost]
public ActionResult GetList()
{
//Server side Parameter.
var start = Request.Form.GetValues("start").FirstOrDefault();
var length = Request.Form.GetValues("length").FirstOrDefault();
string sortColumnName = Request.Form.GetValues("columns[" + Request.Form.GetValues("order[0][column]").FirstOrDefault() + "][name]").FirstOrDefault();
string sortDirection = Request.Form.GetValues("order[0][dir]").FirstOrDefault();
int pageSize = length != null ? Convert.ToInt32(length) : 0;
int skip = start != null ? Convert.ToInt32(start) : 0;
int recordsTotal = 0;
using (eNtsaOnlineRegistrationDBContext db = new eNtsaOnlineRegistrationDBContext())
{
var v = (from a in db.TblEventsManagements select a);
if (!(string.IsNullOrEmpty(sortColumnName) && string.IsNullOrEmpty(sortDirection)))
{
v = v.OrderBy(sortColumnName + " " + sortDirection);
}
recordsTotal = v.Count();
var data = v.Skip(skip).Take(pageSize).ToList();
return Json(new { draw = Request["draw"], recordsFiltered = recordsTotal, recordsTotal = recordsTotal, data = data }, JsonRequestBehavior.AllowGet);
}
}
}
// View cshtml
@{
ViewBag.Title = "EventManagement List";
}
<hr />
<hr />
<hr />
<h2>EventManagement List</h2>
<table id="EventManagementTable" class="ui celled table" style="width:100%">
@*Semantic UI*@
@*<table id="EventManagementTable" class="ui celled table">*@
@*Bootstrap*@
@*<table id="EventManagementTable" class="table table-striped table-bordered">*@
<thead>
<tr>
<th>TrainingType</th>
<th>TrainingDescription</th>
<th>Price</th>
<th>Venue</th>
<th>Facilitator</th>
<th>WhoAttend</th>
<th>RSVP</th>
</tr>
</thead>
<tfoot>
<tr>
<th>TrainingType</th>
<th>TrainingDescription</th>
<th>Price</th>
<th>Venue</th>
<th>Facilitator</th>
<th>WhoAttend</th>
<th>RSVP</th>
</tr>
</tfoot>
</table>
<link href="//cdnjs.cloudflare.com/ajax/libs/semantic-ui/2.2.6/semantic.min.css" rel="stylesheet" />
<link href="https://cdn.datatables.net/1.10.15/css/dataTables.semanticui.min.css" rel="stylesheet" />
@section scripts{
<script src="//cdn.datatables.net/1.10.15/js/jquery.dataTables.min.js"></script>
<script src="https://cdn.datatables.net/1.10.15/js/dataTables.semanticui.min.js"></script>
<script src="//cdnjs.cloudflare.com/ajax/libs/semantic-ui/2.2.6/semantic.min.js"></script>
<script>
$(document).ready(function () {
$("#EventManagementTable").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>
}