zoukankan      html  css  js  c++  java
  • 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);
            }
  • 相关阅读:
    删除List集合中的元素你碰到过这样的陷阱吗?
    从spring框架中的事件驱动模型出发,优化实际应用开发代码
    SpringBoot启动原理及相关流程
    基于SpringBoot实现定时任务的设置(常用:定时清理数据库)
    C#开发中常用的加密解密方法
    http://go.microsoft.com/fwlink/?linkid问题
    移动端开发必须知道的小技巧
    工作中遇到的细节问题总结(二)
    redis分布式锁和消息队列
    join和wait
  • 原文地址:https://www.cnblogs.com/cxd1008/p/8383817.html
Copyright © 2011-2022 走看看