Copied to clipboard

Flag this post as spam?

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


  • Nic Cordingley 9 posts 80 karma points
    Aug 09, 2018 @ 08:44
    Nic Cordingley
    0

    Error -editing partial macro in the umbraco starters guide

    Hi,

    I was editing the 'partial macros' as part of the Umbraco guide and got the following error. As a newbie I have no idea where i went wrong as the replacement code looks fine. Any suggestions?

    Unhandled controller exception occurred System.Web.HttpCompileException (0x80004005): c:\inetpub\temp\DWASFiles\sites\efa10cb2-f07a-44ab-9381-2b62b8591ce0\VirtualDirectory0\site\wwwroot\Views\MacroPartials\LatestBlogposts.cshtml(20): error CS0428: Cannot convert method group 'Count' to non-delegate type 'double'. Did you intend to invoke the method?

  • Jan Skovgaard 11280 posts 23678 karma points MVP 10x admin c-trib
    Aug 09, 2018 @ 08:56
    Jan Skovgaard
    0

    Hello Nic and welcome to our :)

    Can you show the link to the guide you have been following? And can you also please share the code that is causing the issue? That way it will be easier to help you out :)

    Cheers, Jan

  • Nic Cordingley 9 posts 80 karma points
    Aug 09, 2018 @ 09:13
    Nic Cordingley
    0

    Hi Jan,

    It was part of the new starter tutorials. I was following the instructions to 'Add a Blog Post Publication Date'. I changed the items of code as per the instructions below:

    1. Find the element with the class blogpost-date and change it to use a nicely formatted Publication Date, i.e.: @Model.Content.PublicationDate.ToLongDateString()

    2. Scroll down to find the blogpost-date element and change it to use a nicely formatted Publication Date, i.e.: @post.PublicationDate.ToLongDateString() Scroll further back up the page to where we get the blog posts (as the Children of this page). Change this to: var blogposts = startNode.Children.OrderByDescending(x => x.GetPropertyValue

    I then got the error alert and the page looks like this: enter image description here

  • Jan Skovgaard 11280 posts 23678 karma points MVP 10x admin c-trib
    Aug 09, 2018 @ 09:18
    Jan Skovgaard
    0

    Hi Nic

    Just to make sure we're on the same page it would be really helpful if you could paste the link to the place where you got stuck with this issue :)

    And I would also really like to see the entire code you have in your view currently. It makes it much easier to grasp your context. Just copy paste it all in please :) And is it safe to assume you're using Umbraco 7.11?

    Cheers, Jan

  • Nic Cordingley 9 posts 80 karma points
    Aug 09, 2018 @ 09:28
    Nic Cordingley
    0

    Hi,

    https://nics-versatile-deer.s1.umbraco.io/umbraco/ is the link to the guide.

    Code changes are as below.

    1. Blogpost template:

    @inherits Umbraco.Web.Mvc.UmbracoTemplatePage

    @Model.Content.PublicationDate.ToLongDateString() @Html.Partial("~/Views/Partials/CategoryLinks.cshtml", Model.Content.Categories)

    @Model.Content.Excerpt

    @Html.GetGridHtml(Model.Content, "bodyText", "bootstrap3-fluid")

    2: This was the second bit that i changed. Partial Macro>LatestBlogposts.cshtml

    @using ContentModels = Umbraco.Web.PublishedContentModels; @using Umbraco.Web; @inherits Umbraco.Web.Macros.PartialViewMacroPage @{ var startNodeId = Model.MacroParameters["startNodeId"] != null ? Model.MacroParameters["startNodeId"] : Model.Content.Id; var numberOfPosts = 3; if (Model.MacroParameters["numberOfPosts"] != null) { int.TryParse((string)Model.MacroParameters["numberOfPosts"], out numberOfPosts); }

    } @if (startNodeId != null) { @* Get the starting page *@ var startNode = Umbraco.TypedContent(startNodeId); //Gets all blogposts to calculate pages var blogposts = startNode.Children.OrderByDescending(x => x.GetPropertyValue

    if (pagedBlogposts.Count > 0)
    {
        <div class="blogposts">
    
            @foreach (ContentModels.Blogpost post in pagedBlogposts)
            {
                <a href="@post.Url" class="blogpost">
                    <div class="blogpost-meta">
                        <small class="blogpost-date">@post.PublicationDate.ToLongDateString()</small>
                        <small class="blogpost-cat">
                            @Html.Partial("~/Views/Partials/CategoryLinks.cshtml", post.Categories)
                        </small>
                    </div>
                    <h3 class="blogpost-title">@post.PageTitle</h3>
                    <div class="blogpost-excerpt">@post.Excerpt</div>
                </a>
            }
        </div>
    }
    
    if (blogposts.Count > numberOfPosts)
    {
        <div class="pagination">
            <nav class="nav-bar nav-bar--center">
                @if (page <= 1)
                {
                    <span class="nav-link nav-link--black nav-link--disabled">Prev</span>
                }
                else
                {
                    <a class="nav-link nav-link--black" href="@(Model.Content.Url + "?page=" + (page - 1))">Prev</a>
                }
    
                @for (int i = 1; i <= pageCount; i++)
                {
                    <a class="nav-link nav-link--black @(page == i ? "nav-link--active" : null)" href="@(Model.Content.Url + "?page=" + i)">@i</a>
                }
                @if (page == pageCount)
                {
                    <span class="nav-link nav-link--black nav-link--disabled">Next</span>
                }
                else
                {
                    <a class="nav-link nav-link--black" href="@(Model.Content.Url + "?page=" + (page + 1))">Next</a>
                }
    
            </nav>
        </div>
    }
    

    }

  • Jan Skovgaard 11280 posts 23678 karma points MVP 10x admin c-trib
    Aug 09, 2018 @ 18:22
    Jan Skovgaard
    1

    Hi Nic

    Ok, so I had some time to invest this properly this evening. I also managed to find the link to the documentation you quoted above, which is https://our.umbraco.com/documentation/Tutorials/Starter-kit/Lessons/2-Add-a-Blog-Post-Publication-Date/part-2 and https://our.umbraco.com/documentation/Tutorials/Starter-kit/Lessons/2-Add-a-Blog-Post-Publication-Date/part-3

    It's in lesson three things go wrong and think I found the culprit! :)

    The line from the documentation that says:

    var blogposts = startNode.Children.OrderByDescending(x => x.GetPropertyValue<DateTime>("PublicationDate")).Take(3);
    

    Should be changed to this instead, which works when I test it on my local installation so it should also work on yours.

    var blogposts = startNode.Children.OrderByDescending(x => x.GetPropertyValue<DateTime>("PublicationDate")).ToList();
    

    There is no need to add the .Take(3) part since there is some paging logic setup already where there is a "numberOfPosts" variable already being set so it already does this by default so 3 posts are displayed pr. page. However if we just remove the .Take(3) part it will still fail unless we add the .ToList() at the end as I have done in the above example. It was also used in the original "blogposts" variable before it's changed. The stuff that happens in the variable is based on LINQ, which I'm no expert at - I can just see that adding .ToList() makes it work :) So I can't give you a good explanation about how when and why to use .ToList() to be honest.

    Clearly a mistake in the documentation. Once I'm done writing this reply I'll make a PR to have this changed so others don't run into the same issues as you have been struggling with. But before I do I would like to have you confirm that my suggested change is working for you.

    I hope this helps!

    /Jan

  • Nic Cordingley 9 posts 80 karma points
    Aug 09, 2018 @ 09:29
    Nic Cordingley
    0

    The guide is from the 'Help section' when i login so not sure that link will be very helpful

  • Jan Skovgaard 11280 posts 23678 karma points MVP 10x admin c-trib
    Aug 09, 2018 @ 10:13
    Jan Skovgaard
    0

    Aaah, I forgot that it's possible to continue to the guides using the dashboard inside Umbraco - However I'm certain that these are linking to the documentation here on Our :) https://our.umbraco.com/documentation/

    I'll try to have a look later unless someone else beats me to it :)

    /Jan

  • Nic Cordingley 9 posts 80 karma points
    Aug 11, 2018 @ 14:20
    Nic Cordingley
    0

    Hi Jan,

    Thanks for your help with this, your solution did indeed sort the problem out! How do i contact Umbraco to let them know? I imagine anyone using the free trial set-up will encounter the same issue?

    Best regards

    Nic

  • Jan Skovgaard 11280 posts 23678 karma points MVP 10x admin c-trib
    Aug 11, 2018 @ 15:50
    Jan Skovgaard
    0

    Hi Nic

    Very happy to hear that it worked for you :-)

    I have already made a pull request for this issue here https://github.com/umbraco/UmbracoDocs/pull/947

    Anyone can contribute to fixing mistakes in the documentation - on the pages in the documentation there is a link to edit a page or report an issue (If one does not know how to fix it by doing a pull request for instance).

    But should you come across other misinformation while following the tutorials etc. then you can also create issues directly at github here https://github.com/umbraco/UmbracoDocs/issues

    /Jan

  • Jan Skovgaard 11280 posts 23678 karma points MVP 10x admin c-trib
    Aug 15, 2018 @ 05:53
    Jan Skovgaard
    0

    Hi Nic

    My proposed change just got merged into the documentation so now no one else should experience the same issue as you did. Thanks for mentioning it and sorry for the wasted time and bad experience you had to go through.

    Cheers,

    Jan

Please Sign in or register to post replies

Write your reply to:

Draft