Sansar Tiwari (Customer) asked a question.

How to get parent Node url in .Net core renderer sitefinity in content list template

@inject Progress.Sitefinity.AspNetCore.Web.IRequestContext requestContext;

 

I'm using this but only able to get parentId not parent node url

 

@requestContext.PageNode.ParentId

 

Anyone help me


  • Sabrie Nedzhip (Enso DX)

    Hi Sansar,

     

    The requestContext exposes only the properties of the current page node. To get the parent node url you need first to load the parent page node via REST SDK and then access its properties.

     

    Below is an example:

     

    1. @using Progress.Sitefinity.RestSdk.Clients.Pages.Dto
    2. @using Progress.Sitefinity.RestSdk;
    3.  
    4. @inject Progress.Sitefinity.AspNetCore.Web.IRequestContext requestContext
    5. @inject IRestClient restClient;
    6.  
    7. @{
    8. var parentId = requestContext.PageNode.ParentId;
    9. if (parentId != Guid.Empty)
    10. {
    11. var parentNode = await restClient.GetItem<PageNodeDto>(parentId);
    12. var parentNodeUrl = parentNode.ViewUrl;
    13. }
    14. }

    Let me know if this helped.

     

    Regards,

    Sabrie

    Selected as Best
  • Sabrie Nedzhip (Enso DX)

    Hi Sansar,

     

    The requestContext exposes only the properties of the current page node. To get the parent node url you need first to load the parent page node via REST SDK and then access its properties.

     

    Below is an example:

     

    1. @using Progress.Sitefinity.RestSdk.Clients.Pages.Dto
    2. @using Progress.Sitefinity.RestSdk;
    3.  
    4. @inject Progress.Sitefinity.AspNetCore.Web.IRequestContext requestContext
    5. @inject IRestClient restClient;
    6.  
    7. @{
    8. var parentId = requestContext.PageNode.ParentId;
    9. if (parentId != Guid.Empty)
    10. {
    11. var parentNode = await restClient.GetItem<PageNodeDto>(parentId);
    12. var parentNodeUrl = parentNode.ViewUrl;
    13. }
    14. }

    Let me know if this helped.

     

    Regards,

    Sabrie

    Selected as Best
    • Sabrie Nedzhip (Enso DX)

      That's great to hear. Thanks for marking my answer as best 😊