Do you actually need to use FindRootNode? or are you just using that for testing? as it's that method that is the issue, but your method name suggests the second codeblock is what you are really want, and should work (if you remove the first method).
I was just testing, but none of the methods are working. UmbracoHelper is using Node.GetCurrent() everywhere. And that´s throwing the error (null reference)
The current node is "calculated" based on the request, and when you're using ajax, well, the request is not the same as when you actually hit a page in Umbraco.
But you could push the page id with the ajax request, if the node the request came from is important.
Working with Node factory in ajax webservice (find node by name)
Hi I´m using this nice helper class to find nodes by name.
In my case i´m using it in an ajax-json webservice.
The problem comes out when the helper class make use of "Node.GetCurrent()" throwing a "null reference" error.
This is my code:
I guess the scope of Node.GetCurrent() is lost in a webservice.
Any ideas?
Hey Xleon,
Do you actually need to use FindRootNode? or are you just using that for testing? as it's that method that is the issue, but your method name suggests the second codeblock is what you are really want, and should work (if you remove the first method).
Matt
I was just testing, but none of the methods are working.
UmbracoHelper is using Node.GetCurrent() everywhere. And that´s throwing the error (null reference)
Ahh, sorry, my bad, you are right.
You could pull back the root node yourself based on some config, or via xpath and pass that into the method GetChildNodesByName?
Matt
Just another test:
System.NullReferenceException
The current node is "calculated" based on the request, and when you're using ajax, well, the request is not the same as when you actually hit a page in Umbraco.
But you could push the page id with the ajax request, if the node the request came from is important.
Solved !
After reading this post, I added the method GetNodeFromXpath to UmbracoHelper, and this is how I get the root node:
So now, UmbracoHelper would work like this:
Thanks for help!
is working on a reply...