[RESOLVED]How to set Pagination number as 1, 2, 3 …. from my controller ?

Hi

i try to make Pagination to get pages as 1, 2, 3, …. as Bootstarp:

<ul class="pagination">
  <li class="disabled"><a href="#">&laquo;</a></li>
  <li class="active"><a href="#">1 <span class="sr-only">(current)</span></a></li>
  ...
</ul>

but here i don’t know how to pass pages numbers to ( from 1 to end of pages depending on data found ? )

i can do it on;y with Next and Prv button as:

<ul class="pager">
    <li class="previous"><a href="/VisitDatas/Index?Page=@ViewBag.Prv">&larr; Prv</a></li>
    <li class="next"><a href="/VisitDatas/Index?Page=@ViewBag.Nex">Next &rarr;</a></li>
</ul>

and it work fine but i need to make it with Page Number Like (1, 2, 3, …)

C# Code:

        public ActionResult Index(int Page = 0)
        {
            ViewBag.Doctor_ID = new SelectList(db.Doctors, "Doctor_ID", "Doctor_Name");

            var visitDatas = db.VisitDatas.Include(v => v.ClinicCodes).Include(v => v.Doctors).Include(v => v.Kashfs);
            var model = visitDatas.Where(IsDone => IsDone.IsDone == false).ToList().Take(100).OrderByDescending(Visit_Date => Visit_Date.Visit_Date).ThenBy(VisitTime => VisitTime.VisitTime).Skip(25 * Page).Take(25);

            ViewBag.Prv = (Page - 1) < 0 ? 0 : Page - 1;
            ViewBag.Nex = Page + 1;
            return View(model);
        }

so i hope that any one can help me and tell me how can i do it with page number ?

Hi,

For that format, you could base on the current page number to format the pagination number. You may use some plugin to achieve that.

I suggest that you could refer to this link below achieve paging:

# Sorting, Filtering, and Paging with the Entity Framework in an ASP.NET MVC Application

http://www.asp.net/mvc/tutorials/getting-started-with-ef-using-mvc/sorting-filtering-and-paging-with-the-entity-framework-in-an-asp-net-mvc-application

Best Regards

Starain

Leave a Reply