当前位置: 首页 > 工具软件 > MvcPager > 使用案例 >

MVCPager入门实例

楚意
2023-12-01
1.controller写法:
public ActionResult Index(int id = 1)
{
  using (var db = new NORTHWNDEntities())
  {
  PagedList<Orders> orders = db.Orders.OrderBy(o=>o.OrderID).ToPagedList(id, 20);
  return View(orders);
  }
}

 

2.前台页面

@{
    ViewBag.Title = "MvcPager标准Url分页";
}
@model PagedList<Orders>          
<h1>MvcPager标准Url分页</h1>
<table width="98%">
<tr><th>订单编号</th><th>订单日期</th><th>顾客编号</th><th>收货地址</th></tr>
@foreach (Orders od in Model)
 {     
     <tr><td>@od.OrderID</td><td>@od.OrderDate.ToString()</td><td>@od.CustomerID</td>
     <td>@od.ShipAddress</td></tr>   
 }
</table>
 @Html.Pager(Model,new PagerOptions{PageIndexParameterName=" id"})

 

 

转载于:https://www.cnblogs.com/kenny999/archive/2012/01/28/2330300.html

 类似资料: