描述:用mvcpager实现简单分页功能
参考网址:
http://www.cnblogs.com/iamlilinfeng/archive/2013/03/11/2951460.html
http://www.webdiyer.com/aspnetpager/(官网)
view
<%@ Page Language="C#" Inherits="System.Web.Mvc.ViewPage<PagedList<OA_TAB_APPLYLEAVE>>" %> <%@ Import Namespace="Webdiyer.WebControls.Mvc" %> <!DOCTYPE html> <html> <head runat="server"> <title>个人休假申请查询</title> <link href="/CSS/IE6.css" rel="stylesheet" type="text/css" /> </head> <body> <% using (Html.BeginForm("QueryApplyLeave", "LeaveReport", FormMethod.Get)) { %> <div> <table border="0" cellpadding="1" cellspacing="1" width="90%"> <tr> <td align="center" style="font-weight: bold; font-size: 20px"> 个人休假申请查询</td> </tr> </table> </div> <fieldset style=" 90%"> <legend style="font-weight: bold; font-size: 80%">休假申请信息</legend> <table border="0" cellpadding="1" cellspacing="1" class="Table1" width="100%"> <tr> <td style=" 40px">工号:</td> <td> <input id="txtStaffNo" type="text" value="<%=(Session["CurrUser"] as EmployeeInfo).StaffNo %>" name="txtStaffNo" class="EditTextBox1" readonly width="90px" /></td> <td style=" 40px">姓名:</td> <td> <input id="txtStaffName" value="<%=(Session["CurrUser"] as EmployeeInfo).Name %>" type="text" name="txtStaffName" class="EditTextBox1" readonly width="90px" /> </td> <td style=" 40px">部门:</td> <td> <input id="txtDepartment" type="text" value="<%= Html.Action("GetFullDeptName", "LeaveReport", new { staffNo = (Session["CurrUser"] as EmployeeInfo).StaffNo}) %>" name="txtDepartment" class="EditTextBox1" readonly width="110px" /> </td> </tr> <tr> <td colspan="6"> <table cellspacing="0" cellpadding="4" rules="all" border="1" id="ucQueryBalance_GridView1" style="100%;border-collapse:collapse;"> <tr style="color:White;background-color:#006699;"> <td width="90"> PID </td> <td> 开始日期 </td> <td> 结束日期 </td> <td> 请假天数 </td> <td> 休假种类 </td> <td> 备注 </td> <td> 申请日期 </td> <td> 是否提前结束 </td> <td> 状态 </td> <td> 详细 </td> </tr> <%foreach (var o in Model) { %> <tr> <td> <%= Html.Encode(o.OA_LV_PID)%></td> <td> <%= Html.Encode(o.OA_LV_STARTDATE)%></td> <td> <%= Html.Encode(o.OA_LV_ENDDATE)%></td> <td> <%= Html.Encode(o.OA_LV_DURATION)%></td> <td> <%= Html.Encode(o.OA_LV_DESCRIPTION)%></td> <td> <%= Html.Encode(o.OA_LV_REMARK)%></td> <td> <%= Html.Encode(o.OA_LV_ENTERDATE)%></td> <td> <%=Html.Action("GetIsCancel", "LeaveReport", new { isCancel = o.OA_LV_CANCELLEAVE })%> </td> <td> <%=Html.Action("GetStatus", "LeaveReport", new { status = o.OA_LV_STATUS })%></td> <td><a href="/ApplyLeave/Detail" target="_blank">详细</a></td> </tr> <%} %> <tr> <td colspan="10"> <%=Html.Pager(Model, new PagerOptions { PageIndexParameterName = "id", ShowPageIndexBox = true, FirstPageText = "首页", PrevPageText = "上一页", NextPageText = "下一页", LastPageText = "末页", PageIndexBoxType = PageIndexBoxType.DropDownList, PageIndexBoxWrapperFormatString = "请输入页数{0}", GoButtonText = "转到" }) %> 共有 <%=Model.TotalItemCount%> 条记录 <%= Model.CurrentPageIndex%>/<%= Model.TotalPageCount%> </td> </tr> </table> </td> </tr> </table> </fieldset> <%} %> </body> </html>
控制器:
public ActionResult QueryApplyLeave(int? id) { int totalCount = 0; int pageIndex = id ?? 1; LvbalBll lvb = new LvbalBll(); IQueryable<OA_TAB_APPLYLEAVE> query = lvb.GetApplyLeave(this.CurrUser.StaffNo.Trim()); totalCount = query.Count(); PagedList<OA_TAB_APPLYLEAVE> pageList = query.ToPagedList(pageIndex,defaultPageSize); pageList.CurrentPageIndex = pageIndex; pageList.TotalItemCount = totalCount; return View(pageList); }
遇到的问题:
运行后分页中的跳转按钮没反应,查了一下作者的说明文档.
是由于我用的是mvcpager2.0而项目是mvc3.
于是改成低版本的dll就可以了.