MvcPager分页控件
Microsoft Ajax 分页示例
插入分页控件代码:<%=Ajax.Pager(Model, new PagerOptions { PageIndexParameterName = "id" }, new AjaxOptions { UpdateTargetId = "orderdiv" })%>
| 订单编号 | 订单日期 | 顾客编号 | 收货地址 |
|---|---|---|---|
| 10900 | 1998/2/20 0:00:00 | WELLI | Rua do Mercado, 12 |
| 10901 | 1998/2/23 0:00:00 | HILAA | Carrera 22 con Ave. Carlos Soublette #8-35 |
| 10902 | 1998/2/23 0:00:00 | FOLKO | Åkergatan 24 |
| 10903 | 1998/2/24 0:00:00 | HANAR | Rua do Paço, 67 |
| 10904 | 1998/2/24 0:00:00 | WHITC | 1029 - 12th Ave. S. |
| 10905 | 1998/2/24 0:00:00 | WELLI | Rua do Mercado, 12 |
| 10906 | 1998/2/25 0:00:00 | WOLZA | ul. Filtrowa 68 |
| 10907 | 1998/2/25 0:00:00 | SPECD | 25, rue Lauriston |
| 10908 | 1998/2/26 0:00:00 | REGGC | Strada Provinciale 124 |
| 10909 | 1998/2/26 0:00:00 | SANTG | Erling Skakkes gate 78 |
| 10910 | 1998/2/26 0:00:00 | WILMK | Keskuskatu 45 |
| 10911 | 1998/2/26 0:00:00 | GODOS | C/ Romero, 33 |
| 10912 | 1998/2/26 0:00:00 | HUNGO | 8 Johnstown Road |
| 10913 | 1998/2/26 0:00:00 | QUEEN | Alameda dos Canàrios, 891 |
| 10914 | 1998/2/27 0:00:00 | QUEEN | Alameda dos Canàrios, 891 |
| 10915 | 1998/2/27 0:00:00 | TORTU | Avda. Azteca 123 |
| 10916 | 1998/2/27 0:00:00 | RANCH | Av. del Libertador 900 |
| 10917 | 1998/3/2 0:00:00 | ROMEY | Gran Vía, 1 |
| 10918 | 1998/3/2 0:00:00 | BOTTM | 23 Tsawassen Blvd. |
| 10919 | 1998/3/2 0:00:00 | LINOD | Ave. 5 de Mayo Porlamar |
Ajax分页(仅刷新部分页面,Url不改变):
标准Url分页模式(刷新整个页面,Url改变):
<%@ Page Title="" Language="C#" MasterPageFile="~/Views/Shared/Site.Master"
Inherits="System.Web.Mvc.ViewPage<PagedList<Order>>" %>
<%@ Import Namespace="Webdiyer.WebControls.Mvc"%>
<%@ Import Namespace="MvcPagerSample.Models"%>
<asp:Content ID="Content1" ContentPlaceHolderID="TitleContent" runat="server">
ASP.NET MVC Pager 使用 MicrosoftAjax分页示例
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="MainContent" runat="server">
<script language="javascript" type="text/javascript"
src="<%=Url.Content("~/Scripts/MicrosoftAjax.js") %>"></script>
<script language="javascript" type="text/javascript"
src="<%=Url.Content("~/Scripts/MicrosoftMvcAjax.js") %>"></script>
<h2>ASP.NET MVC Pager 使用 MicrosoftAjax分页示例</h2>
<div>本示例演示使用MvcPager配合ASP.NET MVC默认的Ajax引擎实现Ajax分页。</div>
<br />
<%Html.RenderPartial("UCOrderList", Model); %>
</asp:Content>
<%@ Control Language="C#"
Inherits="System.Web.Mvc.ViewUserControl<PagedList<Order>>" %>
<%@ Import Namespace="Webdiyer.WebControls.Mvc"%>
<%@ Import Namespace="MvcPagerSample.Models"%>
<div id="dvOrders">
<table width="98%">
<tr><th>订单编号</th><th>订单日期</th><th>顾客编号</th><th>收货地址</th></tr>
<%foreach(Order od in Model)
{
%>
<tr><td><%=od.OrderID %></td><td><%=od.OrderDate.ToString() %></td>
<td><%=od.CustomerID %></td><td><%=od.ShipAddress %></td></tr>
<%
} %>
</table>
<p>Ajax分页(仅刷新部分页面,Url不改变):</p>
<%=Ajax.Pager(Model, new PagerOptions() { PageIndexParameterName = "id",
ShowPageIndexBox=true,PageIndexBoxType=PageIndexBoxType.DropDownList,
ShowGoButton=false,PageIndexBoxWrapperFormatString="跳转到第{0}页"},
new AjaxOptions() { UpdateTargetId = "dvOrders" })%>
<p>标准url分页(刷新整个页面,Url改变):</p>
<%=Html.Pager(Model, new PagerOptions { PageIndexParameterName = "id",
ShowPageIndexBox = true, PageIndexBoxType = PageIndexBoxType.DropDownList,
PageIndexBoxWrapperFormatString="跳转到第{0}页"})%>
</div>
public ActionResult MsAjaxOrders(int? id)
{
using (var db = new MvcPagerSampleDataContext())
{
PagedList<Order> orders = db.Orders.ToPagedList(id ?? 1, 20);
if (Request.IsAjaxRequest())
return PartialView("UCOrderList", orders);
return View(orders);
}
}
