0

There are many examples of the paged lists in the forum, but I couldn't adapt any of them to my own model, what should I do about it, where did I go wrong? I tried a lot, where is the problem?

@using PagedList
@using PagedList.Mvc
@using DDD.Models
@model IPagedList<Model_Table>

@{
    ViewBag.Title = "Title";
    Layout = "~/Views/Shared/_Layout.cshtml";
}


<h2>mmm</h2>

<div id="table">
    <table>
        <thead>
            <tr>
                <th>Şirket Adı</th>
                <th>Müşteri Adı</th>
                <th>Şehir</th>
            </tr>
        </thead>
        <tbody>
            @foreach (var Item in Model)
            {
                <tr>
                    <td>@Item.DelilListesi.Select(x=>x.Malzeme_Modeli).FirstOrDefault()</td>
                </tr>
            }
        </tbody>
    </table>

    @Html.PagedListPager(Model, _sayfaNo => Url.Action("Index", "Home", new { SayfaNo = _sayfaNo }))
</div>

Controller:

using System;
using System.Linq;
using System.Web.Mvc;
using DDD.Models;
using PagedList;

namespace DDDD.Controllers
{
    public class DenemeController : Controller
    {
        // GET: Deneme
        DDDEntities _db = new DDDEntities();
        public ActionResult Index(int? pagesize)
        {
            int _pagesize = pagesize ?? 1;
            var dddd = from o in _db.table1
                              join a in _db.table2 on o.table1_ID
                              equals a.Table2_ID
                              join c in _db.table3 on a.Table2_ID
                              equals c.table3_ID.ToString()
                              select new D1List
                              {
                                  A1 = o.B1,
                                  A2 = o.B2,
                                  A3 = a.B3,
                              };
            Model_Table model = new Model_Table();
            model.D1Lists = dddd.ToList();
            model.D1Lists.OrderByDescending(m => m.table_name).ToPagedList<D1List>(_pagesize, 10);
            return View(model);
        }
    }
}
Sir Rufo
  • 18,395
  • 2
  • 39
  • 73
lemoncher2
  • 11
  • 4
  • 1
    Does this answer your question? [How to implement pagination in asp.net core razor pages](https://stackoverflow.com/questions/50928891/how-to-implement-pagination-in-asp-net-core-razor-pages) – Sir Rufo Mar 06 '23 at 06:28
  • or maybe https://stackoverflow.com/questions/43736000/pagination-in-a-net-core-api-project/43737694#43737694 – Sir Rufo Mar 06 '23 at 06:29

1 Answers1

0

You mention that you have a problem but there really isn't enough details about what your actual problem is or what unexpected behaviour you are experiencing?

The DenemeController Index method retrieves the data from the database using LINQ-to-SQL queries, and creates a Model_Table object to pass to the view. The pagesize parameter is used to specify the number of items per page in the paged list.

I assume that your Model_Table class has something like so to hold the pagedList

public class Model_Table
{
    public IPagedList<D1List> D1Lists { get; set; }
}

When i have used the PagedList library in the past I have bound my view to my own custom model so using your example, for the model declaration I would change @model IPagedList<Model_Table> to @model Model_Table

Then in the view, since the PagedListPager helper method requires a PagedList.IPagedList object as its first argument i would change yours from

@Html.PagedListPager(Model, _sayfaNo => Url.Action("Index", "Home", new { SayfaNo = _sayfaNo }))

to

@Html.PagedListPager(Model.D1Lists, _sayfaNo => Url.Action("Index", "Home", new { pagesize = _sayfaNo }))

(Basically I am passing in the IPagedList<D1List> D1Lists that is defined on your Model_Table class)

Just looking at the ordering code in your controller and it looks like you are not assigning the result of the OrderByDescending method to any variable, so the ordering operation has no effect on the List. might be better to do

model.D1Lists = dddd.OrderByDescending(m => m.table_name).ToPagedList<D1List>(_pagesize, 10);

Good luck with it.

Paul
  • 620
  • 11
  • 35