I am very new to Umbraco and trying to fix an issue where the TypedContentAtRoot() is returning null. I have to get the URL of a child node 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.
Here is the code I am using to retrieve the parentNode of the current page.
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);
});