您的位置:首页 > 编程语言 > ASP

asp.net mvc 简单分页实现

2017-02-20 22:06 585 查看
分页首先最重要的两个参数就是当前页和页面大小。

在Controller中: <summary>
分页
</summary>
<returns></returns>
public ActionResult Test(string index)
{
if (string.IsNullOrEmpty(index)) //index为当前页,作为参数进行传递
index = "1";
List<User> userlist; //list数据集
int totalCount = 0;
userService = new UserService(); //GetModelList为分页方法,已经进行了封装,10为固定的页面大小
userlist = userService.ConvertListType<User>(userService.GetModelList(string.Empty, "RegTime DESC", Int32.Parse(index), 10, ref totalCount));
return View(userlist);
}
只注意Action中index的传递即可。

<h2>fen ye 信息查询</h2>
@model List<MedCrab.Core.Model.APP.User>
<table>
<tr>
<th>
ID:
</th>
<th>
name:
</th>
<th>
phone:
</th>
<th>
sex:
</th>
</tr>

@foreach (var item in Model)
{
<tr>
<td>
@item.ID
</td>
<td>
@item.fNickName
</td>
<td>
@item.Phone
</td>
<td>
@item.fSex
</td>
</tr>
}
</table>
<ul>@Url.Action("Test", new { index=1 })
<li style='float:left;margin-left:20px;'>
<a style='cursor:pointer;' href="">1</a>
<a style='cursor:pointer;' href="@Url.Action("Test", new { index=2 })">2</a>
<a style='cursor:pointer;' href="@Url.Action("Test", new { index=3 })">3</a>
<a style='cursor:pointer;' href="@Url.Action("Test", new { index=4 })">4</a>
</li>
</ul>a标签中使用Url.Action方法进index的交互。@model强类型进行list数据集的接收。
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  asp.net mvc 分页