Copied to clipboard

Flag this post as spam?

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


  • Matt 308 posts 730 karma points
    Jul 01, 2019 @ 09:35
    Matt
    0

    The name 'nodes' does not exist in the current context

    Hello,

    I'm re creating a website from Umbraco 7 to 8 and coming across an issue;

    I'm getting the following error;

    The name 'nodes' does not exist in the current context

     @foreach(var item in nodes.Skip((page-1)*pageSize).Take(pageSize))
        {
    

    Has something changed?

    Thanks

  • Søren Kottal 530 posts 3521 karma points MVP 2x c-trib
    Jul 01, 2019 @ 10:11
    Søren Kottal
    0

    Hi Matt

    This depends on what nodes is. Can you show some more code?

  • Matt 308 posts 730 karma points
    Jul 01, 2019 @ 10:13
    Matt
    0

    Hello,

    This is the complete code;

    @inherits Umbraco.Web.Mvc.UmbracoViewPage<ContentModels.News>
    @using ContentModels = Umbraco.Web.PublishedModels;
    @{
        Layout = "master.cshtml";
    }
    
    
    int pageSize = 3; // How many items per page
    int page; // The page we are viewing
    
    /* Set up parameters */
    
    if (!int.TryParse(Request.QueryString["page"], out page))
    {
        page = 1;
    }
    
    /* This is your basic query to select the nodes you want */
    
    var nodes = Model.Content.Children.Where(x => x.DocumentTypeAlias == "blogItem").OrderBy("CreateDate desc");
    
    int totalNodes = nodes.Count();
    int totalPages = (int)Math.Ceiling((double)totalNodes / (double)pageSize);
    
    /* Bounds checking */
    
    if (page > totalPages)
    {
        page = totalPages;
    }
    else if (page < 1)
    {
        page = 1;
    }
    
    }
     <div class="body-section">
        <div class="body-container w-container">
          <h1 class="main-page-heading">@Model.Value("blogTitle")</h1>
        @foreach(var item in nodes.Skip((page-1)*pageSize).Take(pageSize))
        {
         <article>
        <div class="blog-item-row w-row">
            <div class="w-col w-col-6">
                <div class="blog-block-left-new">
                    <div class="blog-post-date">@Model.Value(item, "createDate", formatAsDate: true)</div><a href="@item.Url" class="blog-post-title-link">@item.Name</a>
                    <p class="blog-summary-paragraph">@item.GetPropertyValue("blogTeaser")</p>
                    <div class="post-author-title">Added by</div>
                    <div class="post-author">@Model.Value(item, "creatorName")</div>
                </div>
            </div>
            <div class="w-col w-col-6">
                <div class="blog-image-block">
                    <a href="@item.Url">
    
                        @{
                            var blogImage = item.GetPropertyValue<IPublishedContent>("blogImage");
                            if (blogImage != null)
                            {
                                <img src="@blogImage.Url" height="300" width="374" srcset="" class="blog-image">
                            }
                        }
                    </a>
                </div>
            </div>
    </article>
          }
        @{
            if (totalPages > 1)
            {
                <div class="center">
                <div class="pagination">
                        @if (page > 1)
                        {
                            <a href="?page=@(page-1)">Prev</a>
                        }
                        @for (int p = 1; p < totalPages + 1; p++)
                        {
                        <a href="?page=@p" class="@(p == page ? "active" : string.Empty)">@p</a>
                        }
                        @if (page < totalPages)
                        {
                            <a href="?page=@(page+1)">Next</a>
                        }
                </div>
                </div>
            }
            }
              </div>
          </div>
    
  • Søren Kottal 530 posts 3521 karma points MVP 2x c-trib
    Jul 01, 2019 @ 10:21
    Søren Kottal
    0

    Thanks. There is no dynamic access to your content anymore, and some other parts have been moved around, so your var nodes line should read

    var nodes = Model.Children.Where(x => x.ContentType.Alias == "blogItem").OrderByDescending(x => x.CreateDate);

  • Matt 308 posts 730 karma points
    Jul 01, 2019 @ 11:21
    Matt
    100

    Hello,

    Thanks for the heads up, for some reason that line didnt want to display any content. Just a blank page.

    I used the Query builder and got it working with this line;

    var nodes = Umbraco.Content(Guid.Parse("fac06b19-ab57-40f8-bd84-ce8e97ebce96")).Children("newsItem").Where(x => x.IsVisible());
    

    My understanding as well is that we cant use @item.GetPropertyValue("blogTeaser") either so I've changed it to the following @Model.Value("blogTeaser") but nothing renders.

    Any help would be great, seems there are quite alot of changes in Umbraco 8

    Thanks

  • 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