Part 7 - How to retrieve and display data With Paging in the ASP.NET Web API using Jquery

Part7 - Fetch data from WEB Api and Display data with paging using jquery
Part 7 - How to retrieve and display data With Paging in the ASP.NET Web API using Jquery
using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Net.Http;
using System.Web.Http;
using Entities;
using Entities.ViewModel;

namespace WebApiExample.Controllers
{
    public class ExamplePagingController : ApiController
    {
        public HttpResponseMessage Get(int pageNo = 1)
        {
            HttpResponseMessage response = null;
            int totalPage, totalRecord, pageSize;
            pageSize = 5;
            using (MyDatabaseEntities dc = new MyDatabaseEntities())
            {
                totalRecord = dc.Employees.Count();
                totalPage = (totalRecord / pageSize) + ((totalRecord % pageSize) > 0 ? 1 : 0);
                var record = (from a in dc.Employees
                              orderby a.FirstName, a.LastName
                              select a).Skip((pageNo - 1) * pageSize).Take(pageSize).ToList();
                EmployeeDataWithPaging empData = new EmployeeDataWithPaging
                {
                     Employees = record,
                      TotalPage = totalPage
                };
                response = Request.CreateResponse(HttpStatusCode.OK, empData);
            }
            return response;
        }
    }
}

Posted By :