Copied to clipboard

Flag this post as spam?

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


  • Matt 353 posts 825 karma points
    May 09, 2023 @ 08:07
    Matt
    0

    Pageination with umbraco 10

    Hi

    I have an umbraco 8 website, I'm in the process of moving this over to Umbraco 10 but I'm failing with getting pageination to work.

    This is my string for umbraco 8

    if (!int.TryParse(Request.QueryString["page"], out page))
    

    But I get

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

    What would I replace this with?

    Thanks

  • Chriztian Steinmeier 2798 posts 8788 karma points MVP 7x admin c-trib
    May 09, 2023 @ 08:37
    Chriztian Steinmeier
    0

    Hi Matt,

    While I do not really know what I'm doing 😁, I have managed to figure out how to grab stuff from the query string, as that's also a frequent part of my partials.

    You'll need this injection at the top of the file:

    @inject Microsoft.AspNetCore.Http.IHttpContextAccessor HttpContextAccessor;
    

    Then you'll need something like this to make stuff easier to read:

    var httpContext = HttpContextAccessor.HttpContext;
    

    Finally, to grab the value of page, you can do:

    var page = httpContext.Request.Query["page"];
    

    (which you can probably wrap in the TryParse construct).

    Hope that helps,

    /Chriztian

Please Sign in or register to post replies

Write your reply to:

Draft