Last active
March 1, 2016 15:32
-
-
Save glcheetham/dfe7e29c841dc1e53942 to your computer and use it in GitHub Desktop.
Umbraco Image Pagination Concept Explain
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@{ | |
@* 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" /> | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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");