0

I want to paginate using Asp.Net MVC. My table is being loaded with jquery. I tried PagedList but it always showed the same results on other pages. How can I do it the other way? I need to finish quickly today, please help.

public ActionResult Index()
    {
        var sessionId = Convert.ToInt32(Session["UserID"]);
        ViewBag.Name = Session["FirstName"];
        ViewBag.Company = Session["Company"];
        ViewBag.Logo = Session["Logo"];
        List<DetailModel> messages = new List<DetailModel>();
        DetailRepository r = new DetailRepository();
        messages = r.DetailList(sessionId);
        return View(messages.ToList());
    }

public JsonResult DetailList(string basTarih, string bitTarih)
    {
        var sessionId = Convert.ToInt32(Session["UserID"]);

        List<DetailModel> messages = new List<DetailModel>();
        DetailRepository r = new DetailRepository();
        DateTime start = DateTime.MinValue;
        DateTime end = DateTime.MaxValue;
        var sDs = basTarih;
        var eDs = bitTarih;
        DateTime.TryParse(sDs, out start);
        DateTime.TryParse(eDs, out end);
        messages = r.DetailList(sessionId);
        if (start != DateTime.MinValue && end != DateTime.MinValue)
        {
            messages = messages.Where(x => Convert.ToDateTime(x.CreatedDate) >= start && Convert.ToDateTime(x.CreatedDate) <= end).ToList();               
        }
        return Json(messages, JsonRequestBehavior.AllowGet);
    }

<table class="table" id="detailTable">
                            <thead>
                                <tr>
                                    <td>
                                        <span id="clpse-icon" style="color:#5D78FF; padding-left:25px;" onclick="sortTable(0)">
                                            Parça Sayısı
                                            <i class="flaticon2-arrow-down rotate" style="font-size:0.6rem;"></i>
                                        </span>
                                    </td>
                                    <td>
                                        <span id="clpse-icon2" onclick="sortTable(1)" style="padding-left:1px;">Eklenme Tarihi <i class="flaticon2-arrow-down rotate" style="font-size:0.6rem;"></i></span>
                                    </td>
                                    <td></td>
                                </tr>
                            </thead>

                            <tbody id="detailliste"></tbody>

                        </table>
freedomn-m
  • 27,664
  • 8
  • 35
  • 57

1 Answers1

1

You can handle paging by using query string as ?page=

In your c# code, you can use skip and take to get items in page.

You can refer this link for more detail https://stackoverflow.com/a/41327646/4964569

Hien Nguyen
  • 24,551
  • 7
  • 52
  • 62
  • Thank you for the answer. But I couldn't. Can I connect and do if I give a link? I have to solve it very quickly. –  Jun 07 '20 at 10:29