I have successfully loaded the first page with 20 records. I have 100,000 records to load for testing purpose. When I scroll my mouse, it won't invoke my Infinite Scroll action method in my controller.
This is my view page
@{
ViewBag.Title = "Index";
}<div id="tblbody"><table class="table table-responsive table-striped table-bordered" id="tbldata"><thead><tr><th>ID</th><th>Name</th><th>Email</th></tr></thead><tbody id="trow">
@{
Html.RenderAction("table_row", "Employee", new { Model = Model });
}</tbody></table><div id="loadingdiv" style="text-align:center;display:none;margin-bottom:20px;"><img src="~/Images/ajax-loader.gif" /></div></div>
@section scripts {<script>$(document).ready(function () {
var pageindex = 2;
var NoMoredata = false;
var inProgress = false;$(window).scroll(function () {
if ($(window).scrollTop() > Number($("#tblrow").height()) / 2 && !NoMoredata && !inProgress) {
inProgress = true;
$("#loadingdiv").show();$.post("@Url.Action("InfiniteScroll", "Employee")", { "pageindex": pageindex },
function (data) {
pageindex = pageindex + 1;
NoMoredata = data.NoMoredata;$("#trow").append(data.HTMLString);$("#loadingdiv").hide();
inProgress = false;
}
);
}
});
})</script>
}and this is my controller page. I put a break point in this InfiniteScroll action method but it won't come to this break point as i scroll down.
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using WebApplication14.Models;
using WebApplication14.Repository;
namespace WebApplication14.Controllers
{
public class EmployeeController : Controller
{
//
// GET: /Home/
public ActionResult Index()
{
int pagesize = 20;
var rowdata = DataAccess.GetEmployee(1, pagesize);
return View(rowdata);
}
protected string renderPartialViewtostring(string Viewname, object model)
{
if (string.IsNullOrEmpty(Viewname))
Viewname = ControllerContext.RouteData.GetRequiredString("action");
ViewData.Model = model;
using (StringWriter sw = new StringWriter())
{
ViewEngineResult viewresult = ViewEngines.Engines.FindPartialView(ControllerContext, Viewname);
ViewContext viewcontext = new ViewContext(ControllerContext, viewresult.View, ViewData, TempData, sw);
viewresult.View.Render(viewcontext, sw);
return sw.GetStringBuilder().ToString();
}
}
public class JsonModel
{
public string HTMLString { get; set; }
public bool NoMoredata { get; set; }
}
[ChildActionOnly]
public ActionResult table_row(List<Employee> Model)
{
return PartialView(Model);
}
[HttpPost]
public ActionResult InfiniteScroll(int pageindex)
{
System.Threading.Thread.Sleep(1000);
int pagesize = 20;
var tbrow = DataAccess.GetEmployee(pageindex, pagesize);
JsonModel jsonmodel = new JsonModel();
jsonmodel.NoMoredata = tbrow.Count < pagesize;
jsonmodel.HTMLString = renderPartialViewtostring("table_row", tbrow);
return Json(jsonmodel);
}
}
}