I have a ajax call to get attendance of student and returns larger amount of rows (0 - 1,000,000). When 1,000 row exceed browser will fall to 'Out of Memory' error. Also, I need to display the all record on the same page. How can I approch this functionality?
My controller
public JsonResult GetAttendance(int StudentID, int OffSet)
{
var attendanceRecords = mUnitOfWork.StudentAttendanceRepository.GetAll(a => a.StudentID == StudentID, OffSet).ToList();
var jsonResult = Json(attendanceRecords.Select(a => new
{
Date = a.AttendanceDate,
AbsentOrPresent = (bool)a.AbsentOrPresent,
}), JsonRequestBehavior.AllowGet);
jsonResult.MaxJsonLength = int.MaxValue;
return jsonResult;
}
Java script code:
var NoOfRecords = 124512; //student attendance record count taken to here
var OffSet = 0;
var Limit = 1000;
function LoadAttendanceRecords() {
$.ajax({
url: $("#GetAttendance").val(),
type: "POST",
dataType: "JSON",
data: {
StudentID: $("#StudentID").val(),
OffSet: OffSet;
},
success: function(result) {
$.each(result, function(i, o) {
var row = $('#tableAttendance tbody>tr:last').clone(true);
$('label[name="Date"]', row).val(o.Date);
$('label[name="Presence"]', row).val(o.AbsentOrPresent);
$('#tableAttendance tbody').append(row);
}
});
OffSet += Limit;
if (OffSet < NoOfRecords) {
LoadAttendanceRecords();
}
});
}