提问者:小点点

如何在没有PagedList的情况下在ASP.NET MVC中进行分页?


我想使用ASP.NET MVC分页。 我的表正在加载jQuery。 我尝试了PagedList,但它总是在其他页面上显示相同的结果。 我怎么能用另一种方式呢? 我今天需要快点完成,请帮忙。

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>

共2个答案

匿名用户

您可以使用查询字符串作为?page=来处理分页

在C#代码中,可以使用SkipTake获取Page中的项。

您可以参考此链接获得更多详细信息https://stackoverflow.com/a/41327646/4964569

匿名用户

谢谢你的回答。 但我做不到。 我可以连接和做如果我给一个链接? 我得很快解决。