Skip to content

Instantly share code, notes, and snippets.

@glcheetham
Last active March 1, 2016 15:32
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save glcheetham/dfe7e29c841dc1e53942 to your computer and use it in GitHub Desktop.
Save glcheetham/dfe7e29c841dc1e53942 to your computer and use it in GitHub Desktop.
Umbraco Image Pagination Concept Explain
@{
@* Pagination Logic *@
var postsPerPage = 5;
var allPosts = Model.Content.GetPropertyValue<string>("images").Split(',');
allPosts.ToList().ForEach(i => i = Umbraco.TypedMedia(i));
var totalPages = Math.Ceiling((double)(allPosts.Count() / (double)postsPerPage));
var currentPageNo = int.Parse(Request.QueryString["p"] ?? "1");
if (currentPageNo > totalPages) { currentPageNo = 1; }
var currentPostsRange = (currentPageNo * postsPerPage) + postsPerPage;
var currentPagePosts = allPosts.Skip((currentPageNo * postsPerPage) - postsPerPage).Take(postsPerPage);
}
<!-- example to output -->
@foreach(var image in allPosts) {
<img src="image.Url" />
}
@atweedie
Copy link

atweedie commented Mar 1, 2016

Value cannot be null.
Parameter name: source

Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

Exception Details: System.ArgumentNullException: Value cannot be null.
Parameter name: source

Source Error:

Line 6:
Line 7: var allImages = Model.Content.GetPropertyValue<List>("images");
Line 8: var totalPages = Math.Ceiling((double)(allImages.Count() / (double)imagesPerPage));
Line 9:
Line 10: var currentPageNo = int.Parse(Request.QueryString["p"] ?? "1");

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment