I have been using ASP.Net MVC 5 to build my web application, and for pagination purpose I followed the below tutorial.
http://www.asp.net/mvc/overview/getting-started/getting-started-with-ef-using-mvc/sorting-filtering-and-paging-with-the-entity-framework-in-an-asp-net-mvc-application
Everything works out as expected. But my project requires the page list shown in pager to be in Bengali instead of English, depending on the culture information.
E.g. I have the following in my page
1
2
3
But I need it to be
১
২
৩
so the numbers are translated.
Is there a way to achieve that using the PagedList.MVC component I used?
You can use PagedListRenderOptions
to specify a function to format your numbers. Example adapted from documentation on GitHub:
@Html.PagedListPager((IPagedList)ViewBag.OnePageOfProducts,
page => Url.Action("Index", new { page = page }),
new PagedListRenderOptions {
FunctionToDisplayEachPageNumber =
page => page.ToString()
}
)
Key point is this instructions: page => page.ToString()
, default implementation simply does String.Format(LinkToIndividualPageFormat , page)
but you can replace it with your own function (like in previous example).
Unfortunately page.ToString(new CultureInfo("bn-IN"))
won't print 1
as ১
so you have to do it by hand. A very naive example (do not use this, it's terrible and inefficient) just to explain what I mean:
page => page.ToString()
.Replace("1", "\u09e7")
.Replace("2", "\u09e8")
.Replace("3", "\u09e9"); // And so on...