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>

  • 相关阅读:
    Uva 11991 Easy Prblem from Rujia Liu ?
    BANK && IT
    随机数发生器(对拍)-----对比测试
    HDU 1695(GCD)
    欧拉定理与费马定理,离散对数定理
    POJ 2352 (stars)
    线段树
    codeforces 51C(Three Base Stations)
    codeforces 165B(Burning Midnight Oil)
    POJ 2785(4 Values whose Sum is 0)
  • 原文地址:https://www.cnblogs.com/lingr/p/5563469.html
Copyright © 2011-2022 走看看