Copied to clipboard

Flag this post as spam?

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


  • Sharmarke Hujale 103 posts 346 karma points
    Oct 22, 2015 @ 20:05
    Sharmarke Hujale
    0

    Paging in Umbraco 7

    I have some problem on my blog page with regards to paging.. it seems that I can't use my own property "blogSubheader"

    var pageSize = 5;
    
    if (Model.Content.HasValue("numberOfItemsPerPge"))
    {
        pageSize = Model.Content.GetPropertyValue<int>("numberOfItemsPerPage");
    }
    
    var page = 1; int.TryParse(Request.QueryString["page"], out page);
    var items = Model.Content.Children().Where(x => x.IsDocumentType("BlogPost")).OrderByDescending(x => x.CreateDate);
    var totalPages = (int)Math.Ceiling((double)items.Count() / (double)pageSize);
    
    if (page > totalPages)
    {
        page = totalPages;
    }
    else if (page < 1)
    {
        page = 1;
    }
    

    this is what i loop out in my foreach:

                @foreach (var blogPost in items.Skip((page - 1) * pageSize).Take(pageSize).OrderBy(x => x.CreateDate))
                {
                     <!--Article-->
                    <article class="post-preview">
                        <a href="@blogPost.Url">
                            <h2 class="post-title">@blogPost.Name</h2>
                            <h3 class="post-subtitle">@blogPost.blogSubheader</h3>
                        </a>
                        <p class="post-meta">
                            Posted by
                            <a href="@blogPost.Url">@Model.Content.CreatorName</a>
    
                            on @DateTime.Today.ToString("MMMM d, yyyy")
                        </p>
                    </article>
                    <hr />
                }
    

    When I type "blogSubheader" it shows it as an error... And on my blogPost documentype I have the property.

    Hope my question was understandable - thanks in advance!

  • Tim Geyssens 6562 posts 15373 karma points MVP 2x c-trib
    Oct 22, 2015 @ 20:32
    Tim Geyssens
    100

    Hey,

    The type of objects you are working with isn't dynamic so you'll have to fetch the property in a longer syntax like you do here

     pageSize = Model.Content.GetPropertyValue<int>("numberOfItemsPerPage");
    

    so try

    @blogPost.GetPropertyValue<string>("blogSubheader")
    
  • Sharmarke Hujale 103 posts 346 karma points
    Oct 22, 2015 @ 20:55
    Sharmarke Hujale
    0

    When I use it

     <h3 class="post-subtitle">@blogPost.GetPropertyValue<string>("blogSubheader")</h3>
    

    it gives me an error:

    Error: Cannot convert method group 'GetPropertyValue' to non-delegate type 'object'. Did you intend to invoke the method?

  • Sharmarke Hujale 103 posts 346 karma points
    Oct 22, 2015 @ 21:20
    Sharmarke Hujale
    0
     @blogPost.GetPropertyValue("blogSubheader")  
    

    I used this one without the <'string'> and it worked perfectly!

    Thanks mate!

  • This forum is in read-only mode while we transition to the new forum.

    You can continue this topic on the new forum by tapping the "Continue discussion" link below.

Please Sign in or register to post replies