一、引用CSS和JS:

<link href="/Content/Plugins/jQuery.Pagination_v2.2/pagination.css" rel="stylesheet"
type="text/css" />
<script src="/Content/Plugins/jQuery.Pagination_v2.2/jquery.pagination.js" type="text/javascript"></script>
View Code
二、HTML:

<div id="Pagination" class="flickr" style="margin-top: 10px; margin-left: 10px;">
</div>
三、JS:

$(function () {
var total = parseInt("@(ViewBag.total)");
var page = parseInt("@(ViewBag.page)") - 1;
var pageSize = parseInt("@(ViewBag.pageSize)");
$("#Pagination").pagination(total, {
callback: function (page_id) {
window.location = "BoardList?page=" + page_id + "&pageSize=" + this.items_per_page;
}, //PageCallback() 為翻頁調用次函數。
prev_text: " 上一頁",
next_text: "下一頁 ",
items_per_page: 10, //每頁的資料個數
num_display_entries: 1, //兩側首尾分頁條目數
current_page: page, //目前頁碼
num_edge_entries: 11 //連續分頁主體部分分頁條目數
});
});
四、背景代碼:

public ActionResult BoardList()
{
PagerModel pager = new PagerModel();
if (Request["page"] == null)
{
pager.page = 1;
pager.rows = 10;
pager.sort = "Id";
pager.order = "desc";
}
else
{
pager.page = int.Parse(Request["page"]) + 1;
pager.rows = int.Parse(Request["pageSize"]);
pager.sort = "Id";
pager.order = "desc";
}
boardManageService.GetList(ref pager);
List<BoardModel> boardList = pager.result as List<BoardModel>;
ViewData["BoardModelList"] = boardList;
ViewBag.page = pager.page;
ViewBag.total = pager.totalRows;
ViewBag.pageSize = pager.rows;
return View();
}
#endregion