该示例演示使用传统的ADO.NET数据访问技术调用sql server存储过程,使用DataAdapter填充DataTable,并调用PagedList构造函数生成PagedList<DataRow>的分页数据对象从面实现分页。
- Url路由分页
- Ajax分页
- Ajax搜索分页
- 外观样式
- 分页数据相关
- Javascrip API
- AjaxPager 类
- AjaxHelper.Pager 扩展方法
- HtmlPager 类
- HtmlHelper.Pager 扩展方法
- IPagedList 接口
- IPagedList<T> 接口
- MvcAjaxOptions 类
- MvcAjaxOptionsBuilder 类
- PagedList<T> 类
- PageLinqExtensions 类
-
PagerOptions 类
- ActionName属性
- AlwaysShowFirstLastPageNumber属性
- AutoHide属性
- ContainerTagName属性
- ControllerName属性
- CssClass属性
- CurrentPageNumberFormatString属性
- CurrentPagerItemTemplate属性
- DisabledPagerItemTemplate属性
- FirstPageRouteName属性
- FirstPageText属性
- GoToButtonId属性
- HidePagerItems属性
- HorizontalAlign属性
- HtmlAttributes属性
- Id属性
- InvalidPageIndexErrorMessage属性
- LastPageText属性
- MaximumPageIndexItems属性
- MaximumPageNumber属性
- MorePagerItemTemplate属性
- MorePageText属性
- NavigationPagerItemsPosition属性
- NavigationPagerItemTemplate属性
- NextPageText属性
- NumericPagerItemCount属性
- NumericPagerItemTemplate属性
- OnPageIndexError属性
- PageIndexBoxId属性
- PageIndexOutOfRangeErrorMessage属性
- PageIndexParameterName属性
- PageNumberFormatString属性
- PagerItemTemplate属性
- PrevPageText属性
- RouteName属性
- RouteValues属性
- ShowDisabledPagerItems属性
- ShowFirstLast属性
- ShowMorePagerItems属性
- ShowNumericPagerItems属性
- ShowPrevNext属性
- PagerItemsPosition 枚举
- PagerOptionsBuilder 类
- ScriptResourceExtensions 类
- Javascript API
- AjaxPager.cs
- AjaxPagerTest.cs
- DataLoaderBuilder.cs
- DisplayNameExtensions.cs
- HtmlPager.cs
- HtmlPagerTest.cs
- IPagedList.cs
- MvcAjaxOptions.cs
- MvcAjaxOptionsBuilder.cs
- MvcPager.js
- PagedList.cs
- PagedListTest.cs
- PageLinqExtensions.cs
- PagerBuilder.cs
- PagerExtensions.cs
- PagerItem.cs
- PagerItemsPosition.cs
- PagerOptions.cs
- PagerOptionsBuilder.cs
- ScriptResourceExtensions.cs
- TestHelper.cs
MvcPager 分页示例 — 使用存储过程
本示例演示如何使用SQL Server存储过程获取数据配合PagedList来实现分页。
序号 | 文章标题 | 作者 | 文章来源 |
---|---|---|---|
1 | 吴起热线微信公众号上线 | Webdiyer | 吴起热线 |
2 | 再到吴起观“绿海” | Webdiyer | 吴起热线 |
3 | 吴起:从贫困县到全国百强 | Webdiyer | 吴起热线 |
4 | 吴起县铁边城入围全省31个文化旅游名镇 | Webdiyer | 吴起热线 |
5 | 吴起特色养殖成农民致富首选 | Webdiyer | 吴起政府网 |
View:
@model PagedList<article> @Html.Partial("_ArticleTable") @Html.Pager(Model,new PagerOptions{PageIndexParameterName = "id",PagerItemTemplate = "{0} "}) @section Scripts{@{Html.RegisterMvcPagerScriptResource();}}
_ArticleTable.cshtml:
@model PagedList<Article> <table class="table table-bordered table-striped"> <tr> <th class="nowrap">序号</th> <th> @Html.DisplayNameFor(model => model.Title) </th> <th> @Html.DisplayNameFor(model => model.PubDate) </th> <th> @Html.DisplayNameFor(model => model.Author) </th> <th> @Html.DisplayNameFor(model => model.Source) </th> </tr> @{ int i = 0;} @foreach (var item in Model) { <tr> <td>@(Model.StartItemIndex + i++)</td> <td> @Html.DisplayFor(modelItem => item.Title) </td> <td> @Html.DisplayFor(modelItem => item.PubDate) </td> <td> @Html.DisplayFor(modelItem => item.Author) </td> <td> @Html.DisplayFor(modelItem => item.Source) </td> </tr> } </table>
Model:
public class Article { [Display(Name="文章编号")] public int ID { get; set; } [Display(Name="文章标题")] [MaxLength(200)] public string Title { get; set; } [Display(Name = "文章内容")] public string Content { get; set; } [Display(Name = "发布日期")] public DateTime PubDate { get; set; } [Display(Name = "作者")] [MaxLength(20)] public string Author { get; set; } [Display(Name = "文章来源")] [MaxLength(20)] public string Source { get; set; } }
Stored Procedure:
CREATE PROCEDURE [dbo].[USP_GetPagedArticleList] @startIndex int, @endIndex int, @totalItems int output AS WITH artList AS ( SELECT ROW_NUMBER() OVER (ORDER BY A.PubDate DESC)AS Row, A.* from Articles A) SELECT [ID],[Title],[PubDate],[Author],[Source],'' as [Content] FROM artList WHERE Row between @startIndex and @endIndex select @totalItems= count(ID) from Articles
Controller:
public ActionResult StoredProcedure(int id = 1) { using (var db = new DataContext()) { var pageSize = 5; var startIndex = (id - 1)*pageSize + 1; SqlParameter prmStart = new SqlParameter("@startIndex", startIndex); SqlParameter prmEnd = new SqlParameter("@endIndex", startIndex + pageSize); SqlParameter prmTotal = new SqlParameter("@totalItems", SqlDbType.Int); prmTotal.Direction = ParameterDirection.Output; var articles = db.Database.SqlQuery<article>( "exec [USP_GetPagedArticleList] @startIndex,@endIndex,@totalItems out", prmStart, prmEnd, prmTotal).ToList(); var totalItems = (int) prmTotal.Value; var model = new PagedList<article>(articles, id, pageSize, totalItems); return View(model); } }