Fork me on GitHub

MvcPager 分页示例 — 格式化数值页索引

该示例演示如何格式化MvcPager的数值页索引超链接按钮文本。

数值页索引超链接按钮文本格式化字符串可以通过PagerOptions的PageNumberFormatString来设置,当前页数值按钮文本格式化字符串可以通过PagerOptions的CurrentPageNumberFormatString来设置。

请注意,格式化字符串值不应包含html代码,若出现html内容将会被编码显示。

PageNumberFormatString = "[{0}]"

PageNumberFormatString = "[{0}]", CurrentPageNumberFormatString = "{0}"

PageNumberFormatString = "-{0}-"

PageNumberFormatString = "-{0}-", CurrentPageNumberFormatString = "{0}"

View:

@model PagedList<string>
<h6>PageNumberFormatString = "[{0}]":</h6>
@Html.Pager(Model, new PagerOptions { PageIndexParameterName = "id", PageNumberFormatString = "[{0}]" })
<hr />
<h6>PageNumberFormatString = "[{0}]", CurrentPageNumberFormatString = "{0}":</h6>
@Html.Pager(Model, new PagerOptions { PageIndexParameterName = "id", PageNumberFormatString = "[{0}]", CurrentPageNumberFormatString = "{0}" })
<hr />
<h6>PageNumberFormatString = "-{0}-":</h6>
@Html.Pager(Model, new PagerOptions { PageIndexParameterName = "id", PageNumberFormatString = "-{0}-" })
<hr />
<h6>PageNumberFormatString = "-{0}-", CurrentPageNumberFormatString = "{0}":</h6>
@Html.Pager(Model, new PagerOptions { PageIndexParameterName = "id", PageNumberFormatString = "-{0}-", CurrentPageNumberFormatString = "{0}" })

Controller:

        public ActionResult NumericPagerItemsFormat(int id = 1)
        {
            return View(new PagedList<string>(new string[0], id, 1, 80));
        }