Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at

  • Rohan 105 posts 162 karma points
    Sep 12, 2014 @ 16:18

    how to achieve paging in umbraco "cshtml" page?


    I have one page in my website where i need to list all blogs entere from Umbraco CMS.

    There may have hundreds of blogs entere in Umbraco CMS and i need to display it on my front end web site. I know how to iterate through all the blogs on cshtml page and how to display. Right now all the blogs are appear on same page.

    What i need is i need to display 20 blogs on each pages and need to show paging at bottom.

    So how to achieve this ?

    Can anyone please help me here ?

    Thanks in advance !

    Rohan Dave

  • Dan Lister 416 posts 1974 karma points c-trib
    Sep 12, 2014 @ 16:32
    Dan Lister

    Hi Rohan,

    You could pass a page number as a query string parameter to determine which set of blog posts to display. For example, with the below url...


    you could retrieve the correct set of blog posts to return if you wanted to display 10 on each...

        // Get all blog posts
        var posts = Model.Content.Children.Where(c => c.DocumentTypeAlias.Equals("blogPost"));
        // Find the current page number if we have one
        var page = 1;
        if (Request["page"] != null)
            if (!int.TryParse(Request["page"], out page))
                // Default to the first if we don't
                page = 1;
        // Skip all posts before the current page 
        // and take the next 10
        var postsToDisplay = posts.Skip(10 * (page - 1)).Take(10);
        foreach (var post in postsToDisplay)
            // Display blog post

    Thanks, Dan.

Please Sign in or register to post replies

Write your reply to: