Skip to content

Latest commit

 

History

History
66 lines (66 loc) · 2.44 KB

README.md

File metadata and controls

66 lines (66 loc) · 2.44 KB

骏蝶 asp.net core pager 分页系统 Ver1.0.5

有问题请点击上面的“Issues”, Please click on the "Issues" above question.

View:

@addTagHelper "*, jundie.net.core_pager"
@model IEnumerable<jundie.net.core_pager.demo_cn.models.article>
@{
    ViewData["Title"] = "分页示例";
    ViewData["menu_demo"] = "active";
    var pagerOption = ViewData["pagerOption"] as jundie.net.core_pager.PagerOptions;
}
<h3>@ViewData["Message"]</h3>
<div class="panel panel-default">
    <!-- Default panel contents -->
    <div class="panel-heading">
    	@ViewData["Title"] (@pagerOption.Total)
    </div>
    <!-- Table -->
    <table class="table table-striped table-bordered">
        <thead>
            <tr>
                <th>@Html.DisplayNameFor(model => model.Title)</th>
                <th>@Html.DisplayNameFor(model => model.Author)</th>
                <th>@Html.DisplayNameFor(model => model.Source)</th>
            </tr>
        </thead>
        <tbody>
        @foreach (var item in Model)
        {
            <tr>
                <td>@item.Title</td>
                <td>@item.Author</td>
                <td>@item.Source</td>
            </tr>
        }
        </tbody>
    </table>
</div>
<V6-pager pager-option="pagerOption"></V6-pager>
	

Controller:

public IActionResult index(string keyword, int page = 1)
{
    var model = demo_data.AllArticles.OrderByDescending(m => m.PubDate).AsQueryable();
    if (!string.IsNullOrEmpty(keyword))
    {
        model = model.Where(m => m.receiver.Contains(keyword));
    }
    var pagerOption = new PagerOptions
    {
        CurrentPage = page,
        PageSize = 10,
        Total = model.Count(),
        RouteUrl = Url.Action(nameof(Index), new { keyword }),
        PageIndexParameterName = "page"
    };
    ViewData["pagerOption"] = pagerOption;
    var list = model.Skip((pagerOption.CurrentPage - 1) * pagerOption.PageSize).Take(pagerOption.PageSize);
    return View(list);
}