Friday 19 October 2018

Pagination in asp net mvc





Action code:



public ActionResult Index(int? page)

        {

            int pagesize = 6, pageindex = 1;

            pageindex = page.HasValue ? Convert.ToInt32(page) : 1;

            var list = db.tbl_services.OrderByDescending(x => x.s_id).ToList();

            IPagedList<tbl_services> stu = list.ToPagedList(pageindex, pagesize);



            return View(stu);

        }

View code:

@using PagedList.Mvc

@model  PagedList.IPagedList<WebApplication1.Models.tbl_services>







@{

    ViewBag.Title = "Home Page";

}



<div class="row">



    @foreach (var item in Model)

    {

        <div class="col-lg-4 col-md-4 col-sm-4 col-xs-4">

            <img  src="@Url.Content(item.s_img)" style="width:200px; height:200px;"/>

            <h1 style="text-align:center"> @item.s_name</h1>



        </div>



    }

   





</div>

   

    <div>



        <div class="pagination" style="margin-left: 400px">

            Page @(Model.PageCount < Model.PageNumber ? 0 : Model.PageNumber)

            of @Model.PageCount   @Html.PagedListPager(Model, page => Url.Action("Index", new { page }))

        </div>







    </div>


Pass Dynamically Added Html Table Records List To Controller In Asp.net MVC

Controller Code: using System; using System.Collections.Generic; using System.Linq; using System.Web; using System.Web.Mvc; using ...