• MVC Webdiyer.MvcPager 用法


    MVCpager 用法.

    先加个Nuget包 [Webdiyer.MvcPager]

    @using Webdiyer.WebControls.Mvc
    @model PagedList<Model.User>
    @{
        ViewBag.Title = "Users Index";
    }
    <h2>Users Index</h2>
    
    @*此处通过RouteValueDictionary.把所要查询的参数通用URL保存起来.翻页时保留查询条件*@
    @using (Html.BeginForm("Index", "Users", new RouteValueDictionary { { "id", "" } }, FormMethod.Get, new { @class = "form-inline" }))
    {
        <input type="text" id="UserName" name="UserName" placeholder="UserName" class="form-control" value="@Request.QueryString["UserName"]" />
        <button id="submit1" type="submit" class="btn  btn-primary"><i class="fa fa-search"></i> Search</button>
        <a href="~/Users/Users/Create" class="btn btn-success pull-right"><i class="fa fa-plus-circle"></i> Create New</a>
    }
    <br />
    
    <table class="table table-hover">
        <tr>
            <th>
                @Html.DisplayNameFor(model => model.UserName)
            </th>
            <th>
                @Html.DisplayNameFor(model => model.Name)
            </th>
            <th>
                @Html.DisplayNameFor(model => model.IsDisabled)
            </th>
            <th></th>
        </tr>
    
        @foreach (var item in Model)
        {
            <tr>
                <td>
                    @Html.DisplayFor(modelItem => item.UserName)
                </td>
                <td>
                    @Html.DisplayFor(modelItem => item.Name)
                </td>
                <td>
                    @item.IsDisabled
                </td>
                <td>
                    @Html.ActionLink("Edit", "Edit", new { id = item.Id }) |
                    @Html.ActionLink("Details", "Details", new { id = item.Id }) |
                    @Html.ActionLink("Delete", "Delete", new { id = item.Id })
                </td>
            </tr>
        }
    
    </table>
    
    <table>
        <tr>
            @*第几页/共几页 共几条*@
            @*<td width="200px">
                    @Model.CurrentPageIndex / @Model.TotalPageCount  All counts - @Model.TotalItemCount
                </td>*@
            <td>
                @*bootstrap样式*@
                <nav>
                    @Html.Pager(Model, new PagerOptions
               {
                   PageIndexParameterName = "id",
                   NumericPagerItemCount = 5,
                   FirstPageText = "|<",
                   PrevPageText = "<",
                   NextPageText = ">",
                   LastPageText = ">|",
                   ContainerTagName = "ul",
                   CssClass = "pagination",
                   CurrentPagerItemTemplate = "<li class="active"><a href="#">{0}</a></li>",
                   DisabledPagerItemTemplate = "<li class="disabled"><a>{0}</a></li>",
                   PagerItemTemplate = "<li>{0}</li>",
                   Id = "bootstrappager"
               })
                </nav>
            </td>
        </tr>
    </table>

    后台方法.部分:

     public List<User> GetUserList(string UserName, int id)
            {
                var user = db.User.AsQueryable();
                if (!string.IsNullOrEmpty(UserName))
                {
                    user = user.Where(u => u.UserName.Contains(UserName));
                }
                //默认最多查询100条数据.超出100条.查询是没有意义的,用户不会在众多数据中手动查询
                user = user.OrderBy(u => u.Id).Take(100);
                return user.ToPagedList(id, 10);
            }
  • 相关阅读:
    【Idea】使用中的一些问题
    【Redis】Linux配置Redis(单点)
    【Zookeeper】Linux上安装zookeeper(单节点)
    【Echarts】设置主题、扇形格式化
    【JS】两个数组的交集、差集、并集、补集、去重
    【MySQL】 准确查询空值、ISNULL函数
    【健康】能量系统与训练应用和心肺耐力与运动表现
    【RabbitMQ】消息队列RabbitMQ与Spring集成
    【Java、Util】元和分的相互转换
    k8s入门系列之介绍篇
  • 原文地址:https://www.cnblogs.com/cxd1008/p/8383817.html
Copyright © 2020-2023  润新知