Fork me on GitHub

MvcPager demo - Numeric pager item format

This sample demonstrates how to format the text of the numeric pager items.

PagerOptions.PageNumberFormatString property is used to format the text of the numeric pager items including the current page pager item, you can use PagerOptions.CurrentPageNumberFormatString to set the format string for the text of the current page pager item separately.

Note: format strings should not contain any html code!

PageNumberFormatString = "[{0}]"

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

PageNumberFormatString = "-{0}-"

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

View:

        
@model PagedList<string>
<pre>PageNumberFormatString = "[{0}]"</pre>
@Html.Pager(Model, new PagerOptions { PageIndexParameterName = "id", PageNumberFormatString = "[{0}]" })
<hr />
<pre>PageNumberFormatString = "[{0}]", CurrentPageNumberFormatString = "{0}"</pre>
@Html.Pager(Model, new PagerOptions { PageIndexParameterName = "id", PageNumberFormatString = "[{0}]", CurrentPageNumberFormatString = "{0}" })
<hr />
<pre>PageNumberFormatString = "-{0}-"</pre>
@Html.Pager(Model, new PagerOptions { PageIndexParameterName = "id", PageNumberFormatString = "-{0}-" })
<hr />
<pre>PageNumberFormatString = "-{0}-", CurrentPageNumberFormatString = "{0}"</pre>
@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));
        }