Copied to clipboard

Flag this post as spam?

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


  • Suhasini 3 posts 73 karma points
    Dec 22, 2019 @ 10:54
    Suhasini
    0

    Need to get URL of child node in Umbraco

    Hi,

    I am very new to Umbraco and trying to fix an issue where the TypedContentAtRoot() is returning null. Here is the code I am using to retrieve the homeNode of the current page.

    I have to get the URL of a child page that the user has to be redirected to after clicking a button. The child page has been added to the parent page as a descendant and I have confirmed the same.

         var umbracoHelper = new UmbracoHelper(UmbracoContext.Current); 
          var homeNode = umbracoHelper.TypedContentAtRoot().Where(w => 
                                        w.ContentType.Alias.Equals("HomePage"));
         var descendants =homeNode.DescendantsOrSelf("SubmittedPage");
         var confirmationPage = descendants.FirstOrDefault();
    return confirmationPage?.Url;
    

    To also verify this, I performed a check where I can get the current PageID and that is also being returned as null

    var currentPageId = UmbracoContext.Current.PageId;
    

    Basically I have a main HomePage as a document type. It has various child pages that I have verified exists. There is some jQuery validation that sends a get Request to retrieve the confirmationPage Url as shown in the code below.

    $.get('/Umbraco/Api/ConfirmationPageUrl',
    function(data) {      
      window.location.replace(data);
    });
    
  • Nigel Wilson 944 posts 2076 karma points
    Dec 22, 2019 @ 17:55
    Nigel Wilson
    0

    Hi Suhasini

    When querying like you are you need to use the Document Type Alias.

    So, wonderin if you have confirmed the Homepage has a document type alias of "HomePage" (capital H) ?

    Typically document types aliases are camel case and so might be a lower case "h".

    Cheers

    Nigel

  • Suhasini 3 posts 73 karma points
    Dec 29, 2019 @ 09:34
    Suhasini
    0

    Yes, I just rewrote the word "HomePage" before posting the code on a forum. But it was upper camelcase and I reconfirmed it.

    However I also found a solution to the problem.

    I had to create the Content-Type of the page I was looking for. Since the content-type of the page wasnt created the result was returning null.

Please Sign in or register to post replies

Write your reply to:

Draft