Copied to clipboard

Flag this post as spam?

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


  • James 251 posts 1169 karma points
    Aug 20, 2014 @ 12:38
    James
    0

    A foreach problem

    Consider the following code:

    @{

        var pageSize = 9;

        var page = 1; int.TryParse(Request.QueryString["page"], out page);

        var items = Umbraco.TypedContent(Model.Content.Id).Children.Where(x => x.DocumentTypeAlias == "PortfolioItem" && x.IsVisible());

        var totalPages = (int)Math.Ceiling((double)items.Count() / (double)pageSize);

        if (page > totalPages)

        {

            page = totalPages;

        }

        else if (page < 1)

        {

           page = 1;

        }

    }

    SECOND PART OF THE CODE

     

     

     

     

    In the second section of the code i need to be able to encapsulate 3 of the items generated in the foreach with a

    Anyone have any idea how id go about doing this?
    Kind regards.
    James.

     

  • Jeavon Leopold 3074 posts 13632 karma points MVP 11x admin c-trib
    Aug 20, 2014 @ 12:41
    Jeavon Leopold
    0

    Hi James,

    Could you try to repost with the markdown editor and mark the code sections with the "code sample" button so that we can hopefully see it all?

    Jeavon

  • Dan Lister 416 posts 1974 karma points c-trib
    Aug 21, 2014 @ 14:22
    Dan Lister
    0

    Here is James' code:

    @{
        var pageSize = 9;
        var page = 1; 
    
        int.TryParse(Request.QueryString["page"], out page);
    
        var items = Umbraco.TypedContent(Model.Content.Id).Children.Where(x => x.DocumentTypeAlias == "PortfolioItem" && x.IsVisible());
        var totalPages = (int)Math.Ceiling((double)items.Count() / (double)pageSize);
    
        if (page > totalPages)
        {
            page = totalPages;
        }
        else if (page < 1)
        {
           page = 1;
        }
    }
    

    And the second part:

    @foreach (var item in items.Skip((page - 1) * pageSize).Take(pageSize).OrderBy(x => x.Name))
    {
        @item.GetPropertyValue("PortfolioItemTitle")
        @item.Name
        @(Umbraco.Truncate(item.GetPropertyValue("PortfolioItemBodyText").ToString(), 100, false))
    
        Read More
    }
    
  • Jeavon Leopold 3074 posts 13632 karma points MVP 11x admin c-trib
    Aug 21, 2014 @ 16:59
    Jeavon Leopold
    0

    Cool, and what did you want to encapsulate it with?

Please Sign in or register to post replies

Write your reply to:

Draft