一. 将mvcpager ddl 引用到web服务项目中.
二.
在view加入
<%@ Import Namespace="Webdiyer.WebControls.Mvc" %>
@Page 的Inherits属性改为
Inherits="System.Web.Mvc.ViewPage<PagedList<SuppliersInfo>>"
三
控制器那边 定义action 如:
public ActionResult List(int? id)
{
IList<SuppliersInfo> suppliersList = Suppliers.Instance.GetSupplierList(); //返回列表
PagedList<SuppliersInfo> orders = new PagedList<SuppliersInfo>(suppliersList,id?? ,); //定义分页
return View(orders);
}
响应的视图那边: (示例)
<% if (Model.Count > )
{ %>
<% foreach (SuppliersInfo suppliers in Model) //Model是mvcpager中的一个属性, 具体看vs那边的注释
{ %>
<tr>
<td><% = suppliers.SupplierId.ToString()%></td>
<td><% = suppliers.SupplierNo.ToString()%></td>
<td><% = suppliers.SupplierName.ToString()%></td>
<td><% = suppliers.Intro.ToString()%></td>
<td><% = suppliers.Contactor.ToString()%></td>
<td><% = suppliers.Telephone.ToString()%></td>
</tr>
<% }%>
<%} %>
<%else
{%>
<tr><td colspan="">无任何数据</td></tr>
<%} %> </table>
<%=Html.Pager(Model, new PagerOptions { PageIndexParameterName = "id" })%>
四
Global中定义路由:
//自定义的分页路由,示例项目中的“自定义路由分页”示例中用
routes.MapRoute("Paging", "{controller}/{action}/employee_{employeeId}/page_{pageIndex}",
new
{
controller = "Orders",
action = "EmployeeOrders",
emplyeeId = "",
pageIndex = UrlParameter.Optional
});