Copied to clipboard

Flag this post as spam?

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


  • rj 8 posts 99 karma points
    Oct 24, 2018 @ 22:12
    rj
    0

    Getting Current Page in Grid Partial

    Hi,

    I'm in a position where I need to reference information about the current page inside of the grid partial (Views/Partials/Grid).

    Currently I use the following method

    int? pageid = UmbracoContext.Current.PageId;
    IPublishedContent page = Umbraco.TypedContent(pageid);
    

    But I am unsure if this will cause unnecessary overhead as this grid will be used on every page on the website (sans the homepage).

    Will pulling the current page from the cache in a grid cause a noticeable or unnecessary overhead?

    Or is there some way for the current page to be exposed to me instead?

  • Garðar Þorsteinsson 113 posts 534 karma points
    Oct 24, 2018 @ 23:00
    Garðar Þorsteinsson
    100

    Hi,

    You should be able to use Model.Content to access the current node you are on.

    Other option is using for example

    IPublishedContent currentNode = UmbracoContext.Current.PublishedContentRequest.PublishedContent;
    

    Hope this helps.

  • rj 8 posts 99 karma points
    Oct 24, 2018 @ 23:14
    rj
    0

    The model on grid templates seems to be only a dynamic of the contents of the grid, which doesn't expose Model.Content. It may be because I'm inheriting from UmbracoViewPage<dynamic> though.

    UmbracoContext.Current.PublishedContentRequest.PublishedContent appears to be what I was looking for, thank you very much :)

Please Sign in or register to post replies

Write your reply to:

Draft