0

経由でインストールPagedListしてPagedList.Mvcパッケージ化しNuGetました。次に、次のように使用しました。

@using PagedList;
@using PagedList.Mvc;

@model IPagedList<Employee>

@{
    ViewBag.Title = "ListEmployees";
}

<h3>All Employees (@ViewBag.TotalEmployees)</h3>

@if(Model.Count > 0)
{
    foreach(var item in Model)
    {
        Html.RenderPartial("Employee.Card", item);
    }

    @Html.PagedListPager((IPagedList)Model, page => Url.Action("List", new { page = page }), PagedListRenderOptions.Minimal)
}
else
{
    @: no records were found. Sorry
}

コントローラー内のコードで:

public class EmployeeController : Controller
{
    private IRepository<Employee> repository; 
    private Int32 PageSize = 10;

    public EmployeeController(IRepository<Employee> repository)
    {
        this.repository = repository;
    }

    public ActionResult List(Int32? page)
    {
        var set = repository.Get();
        ViewBag.TotalEmployees = set.Count();

        return View(set.ToPagedList(page ?? 1, PageSize));
    }
}

結果として、スタイルが設定されていない順序付けられていないリストを持つのは正常ですか。カスタム スタイルをページャーに適用するにはどうすればよいでしょうか。

ありがとう!

4

1 に答える 1

4

PagedList nuget パッケージの作成者はこちら。

正直なところ、何が起こっているのかわかりません。かなり奇妙に思えます。あなたが与えた説明に基づく私の最善の推測はUrl.Action("List", new {page = page})、nullまたは空の値を返しているため、href属性がレンダリングされないことです。ビューの別の場所に次のコードを追加して、実際の URL が返されることを確認することで、これをテストできます。

<p>@Url.Action("List", new {page = 1})</p>

その段落タグが空の場合、ルーティングに問題がある可能性が最も高くなります。

于 2012-04-19T12:12:22.230 に答える