Get value from Umbraco page in generic controller
# help-with-umbraco
t
Hi I have a generic controller and want to get a value stored in Umbraco 13 on a page called Product which is under the Home page. Normally I can use the render controller which gives the current page but on this occasion I can't. How could I get that value in a non render controller class? Thanks
p
Hi! There are a few ways to do this. Non-render controllers don't know anything about the current page. So you should either send over the page id and retrieve the page or search the tree for your product page
t
Do you have a sample code of searching the tree? I tried UmbracoHelper but that didn't work. All the documentations I've read seem to accept an id/guid but ideally searching the tree would be my preferred approach. 👍
p
What version are you using? And what sort of controller are you using? ApiController or SurfaceController?
k
https://docs.umbraco.com/umbraco-cms/implementation/services#accessing-published-content-outside-of-a-http-request has some examples and explains why directly injecting the
UmbracoHelper
won't work.
t
It's a generic MVC controller
Will give this a read, thx
5 Views