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>

posted @ 2016-06-06 13:09  chenglingr  阅读(246)  评论(0编辑  收藏  举报
生活在继续,我们需要活着