Permalink
Browse files

Added AlwaysAddFirstPageNumber configuration option to force the page…

… number to be set for page 1.
  • Loading branch information...
martijnboland committed Apr 27, 2012
1 parent a12a1af commit 8e4b96333715001702b87bc8a012ee7ebe5d1e72
@@ -61,7 +61,11 @@
}
</tbody>
</table>
- @Html.Pager(Model.PageSize, Model.PageNumber, Model.TotalItemCount).Options(o => o.DisplayTemplate("BootstrapPagination").MaxNrOfPages(14))
+ @Html.Pager(Model.PageSize, Model.PageNumber, Model.TotalItemCount).Options(o => o
+ .DisplayTemplate("BootstrapPagination")
+ .MaxNrOfPages(14)
+ .AlwaysAddFirstPageNumber()
+ )
</div>
<!-- /container -->
</body>
View
@@ -165,7 +165,7 @@ private string GeneratePageUrl(int pageNumber)
var routeDataValues = viewContext.RequestContext.RouteData.Values;
RouteValueDictionary pageLinkValueDictionary;
// Avoid canonical errors when page count is equal to 1.
- if (pageNumber == 1)
+ if (pageNumber == 1 && ! this.pagerOptions.AlwaysAddFirstPageNumber)
{
pageLinkValueDictionary = new RouteValueDictionary(this.pagerOptions.RouteValues);
if (routeDataValues.ContainsKey("page"))
@@ -11,6 +11,7 @@ public class PagerOptions
public string DisplayTemplate { get; internal set; }
public int MaxNrOfPages { get; internal set; }
public AjaxOptions AjaxOptions { get; internal set; }
+ public bool AlwaysAddFirstPageNumber { get; internal set; }
public PagerOptions()
{
@@ -92,6 +92,20 @@ public PagerOptionsBuilder MaxNrOfPages(int maxNrOfPages)
return this;
}
+ /// <summary>
+ /// Always add the page number to the generated link for the first page.
+ /// </summary>
+ /// <remarks>
+ /// By default we don't add the page number for page 1 because it results in canonical links.
+ /// Use this option to override this behaviour.
+ /// </remarks>
+ /// <returns></returns>
+ public PagerOptionsBuilder AlwaysAddFirstPageNumber()
+ {
+ this.pagerOptions.AlwaysAddFirstPageNumber = true;
+ return this;
+ }
+
/// <summary>
/// Set the AjaxOptions.
/// </summary>

0 comments on commit 8e4b963

Please sign in to comment.