zoukankan      html  css  js  c++  java
  • MVC系列-9.查询和分页

    1.增加名字搜索功能

    (1)去ViewsàAccountàIndex.cshtml 中添加一个text box用来传递这个过滤值。

    wps65FF.tmpwps6620.tmp

    (2)修改Index方法,增加条件筛选功能。

    wps6621.tmp

    2.增加分页功能(使用PagedList.MVC)

    参考资料:http://www.bubuko.com/infodetail-672545.html

    (1)用nuget安装PagedList.MVC

    wps6622.tmp

    (2)AccountController.cs中先添加声明。

    using PagedList;

    using System.Configuration;

    (3)Web.Config里<appsettings>加上

    <add key="pageSize" value="5"/>

    (4)AccountController.cs增加action--Index1

    wps6633.tmp

    (5)增加view--Index1

    顶部加上

    @model PagedList.IPagedList<MVCDemo.Models.Account>

    @using PagedList.Mvc

    显示内容及分页

    <table class="table table-striped">

    <thead>

    <tr>

    <th>邮箱</th>

    <th>地址</th>

    <th></th>

    </tr>

    </thead>

    <tbody>

    @foreach (MVCDemo.Models.Account item in Model)

                    {

    <tr>

    <td>@item.Email</td>

    <td>@item.Address</td>

    <td>

    @Html.ActionLink("详情", "Detail", new { id = item.ID })

    @Html.ActionLink("编辑", "Edit", new { id = item.ID })

    @Html.ActionLink("删除", "Delete", new { id = item.ID })

    </td>

    </tr>

                    }

    </tbody>

    </table>

    <div>每页 @Model.PageSize 条记录,共 @Model.PageCount 页,当前第 @Model.PageNumber 页 @Html.PagedListPager(Model,page=>Url.Action("Index1",new { page}))</div>

  • 相关阅读:
    git查看工作状态和历史提交
    PowerDesigner工具栏palette的方法
    WCF证书制作
    ASP.NET.4 高级程序第4版 第3章Web窗体
    tbar居右显示的两种方法
    测试
    转载extj grid
    正值
    网站HTML,XHTML,XML,WML,CSS等测试验证工具介绍[转]
    SQL Server 启用“IP+端口”连接
  • 原文地址:https://www.cnblogs.com/lingr/p/5563469.html
Copyright © 2011-2022 走看看