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数据集的接收。
在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 简单的分页思想与实现
- ASP.NET MVC 简单的分页思想与实现
- ASP.NET MVC 简单的分页思想与实现
- asp.net mvc简单实现基于Razor的分页控件
- ASP.NET MVC 简单的分页思想与实现
- ASP.NET MVC 简单的分页思想与实现
- 艾伟_转载:ASP.NET MVC分页的实现
- ASP.NET MVC 超简单 分页
- 简单的存储过程实现asp.net中的分页
- ASP.net C# 非常简单的实现分页
- 如何应用Asp.Net Mvc内建功能(DefaultModelBinder)实现简单类型、复杂类型、集合类型,以及字典类型的自动绑定
- ASP.NET MVC 3让依赖注入实现得更简单
- asp.net webform实现mvc的简单方法
- 我要学ASP.NET MVC 3.0(十九): MVC 3.0 实例之使用开源控件实现表格排序和分页
- dhl:asp.net mvc下用jQuery ajax方法实现无刷新分页(用户控件)& 整体页面无刷新(2010-11-13 add)
- 【EntityFramework系列教程三,翻译】在ASP.NET MVC程序中使用EntityFramework对数据进行排序、过滤筛选以及实现分页
- ASP.NET MVC分页的实现(上)
- ASP.NET MVC 3.0学习系列(19)-开源控件实现表格排序和分页
- ASP.NET MVC实现(查询+分页)
- ASP.NET 简单分页实现