Copied to clipboard

Flag this post as spam?

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


  • Marc 50 posts 182 karma points
    Nov 24, 2020 @ 17:02
    Marc
    0

    Hello !

    I'm trying to adapt a pagination code to my configuration but I got this error : CS0103: The name 'item' does not exist in the current context

    I don't understand why.

    @inherits Umbraco.Web.Mvc.UmbracoViewPage
    @using ContentModels = Umbraco.Web.PublishedModels
    @using Umbraco.Web.Models;
    
    @{
        var pageSize = 12;
    
    
        var page = 1; int.TryParse(Request.QueryString["page"], out page);
        var items = Umbraco.Content(Guid.Parse("4bf52779-a620-4cc3-8679-c78537e7de27")).ChildrenOfType("evenement").Where(x => x.IsVisible()).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;
        }
    
        <div class="container margin-small">
        <div class="row">
    
        foreach (ContentModels.Evenement item in items.Skip((page - 1) * pageSize).Take(pageSize))
        {
    
                <div class="col-12 col-md-4 d-flex">
                    <a class="events-listing-link flex-fill" href="@item.Url">
                        <h4 class="events-listing-title">@item.EventTitle</h4>
                        <p>@item.EventShortDescription</p>
                        <div class="flexible"></div>
                        <div class="events-listing-date text-center">
                            <p>@item.EventDate.ToString("dd MMMM yy")</p>
                        </div>
                        <div class="button-2 text-center">
                            <p>En savoir plus</p>
                        </div>
                    </a>
                </div>
        }
    
        </div>
        </div>
    
       if (totalPages > 1)
       {
           <div class="pagination">
               <ul>
                   @if (page > 1)
                   {
                       <li><a href="?page=@(page-1)">Prev</a></li>
                   }
                   @for (int p = 1; p < totalPages + 1; p++)
                   {
                       <li class="@(p == page ? "active" : string.Empty)">
                           <a href="?page=@p">@p</a>
                       </li>
                   }
                   @if (page < totalPages)
                   {
                       <li><a href="?page=@(page+1)">Next</a></li>
                   }
               </ul>
           </div>
        }
    }
    

    If you could help, thanks a lot :)

  • Marc Goodson 2141 posts 14324 karma points MVP 8x c-trib
    Nov 24, 2020 @ 17:14
    Marc Goodson
    100

    Hi Marc

    If you stick an @ infront of the foreach does that make a difference?

     @foreach (ContentModels.Evenement item in items.Skip((page - 1) * pageSize).Take(pageSize))
        {
    
                <div class="col-12 col-md-4 d-flex">
                    <a class="events-listing-link flex-fill" href="@item.Url">
                        <h4 class="events-listing-title">@item.EventTitle</h4>
                        <p>@item.EventShortDescription</p>
                        <div class="flexible"></div>
                        <div class="events-listing-date text-center">
                            <p>@item.EventDate.ToString("dd MMMM yy")</p>
                        </div>
                        <div class="button-2 text-center">
                            <p>En savoir plus</p>
                        </div>
                    </a>
                </div>
        }
    

    regards

    Marc

  • Marc 50 posts 182 karma points
    Nov 24, 2020 @ 17:15
    Marc
    0

    I'm so dumb, That was the issue.

    Thanks very much, I've been too long in front of my pc today x)

    thx a lot !

Please Sign in or register to post replies

Write your reply to:

Draft