First post. So please feel free point out if I break any rules or do anything completely wrong.
I've searched and looked what feels like everywhere, but I can't seem to find information about how to fetch content though the UmbracoApiController.
Why I need it:
I want to show all childNodes under a certain city and give the user the possibility to sort them based on tags. I also want to show some basic stuff like some of the tags and certain fields in the page. I plan to do this via JSON and JavaScript. But if there's a better, more effiecent way. Please go ahead and tell me.
What I've done so far:
I've simply created the controller, inhereting from UmbracoApiController. What I don't seem to figure out is how to access the content. I want a list with all the child pages of the city. So I can access the data via JavaScript and show them from there. I've checkboxes for different tags and I want to sort the list automaticly when a user clicks a checkbox.
Thanks for your reply. I've looked through it and tried it but all I seem to get is empty arrays when I return the query result from the API controller. Is it possible that I have to make an JSON object of the information myself or should it return the page and its values as an JSON-object?
Extra question: How do I get the children of one object? It seems like I can only access content, media etc and not its children. Couldn't find anything in the link.
Access content though UmbracoApiController
Hi guys,
First post. So please feel free point out if I break any rules or do anything completely wrong.
I've searched and looked what feels like everywhere, but I can't seem to find information about how to fetch content though the UmbracoApiController.
Why I need it: I want to show all childNodes under a certain city and give the user the possibility to sort them based on tags. I also want to show some basic stuff like some of the tags and certain fields in the page. I plan to do this via JSON and JavaScript. But if there's a better, more effiecent way. Please go ahead and tell me.
What I've done so far: I've simply created the controller, inhereting from UmbracoApiController. What I don't seem to figure out is how to access the content. I want a list with all the child pages of the city. So I can access the data via JavaScript and show them from there. I've checkboxes for different tags and I want to sort the list automaticly when a user clicks a checkbox.
Regards, The Newbie
Hi Daniel,
you can use IPublishedContent for accessing the content.
You can find the documentation with exemples here: https://our.umbraco.org/documentation/Implementation/Query-Data/UmbracoHelper/
Hope this helps?
Best, Sören
Hi Sören,
Thanks for your reply. I've looked through it and tried it but all I seem to get is empty arrays when I return the query result from the API controller. Is it possible that I have to make an JSON object of the information myself or should it return the page and its values as an JSON-object?
Extra question: How do I get the children of one object? It seems like I can only access content, media etc and not its children. Couldn't find anything in the link.
Thanks for your help!
Hi Daniel,
please have a look to the first example in the link:
Here you can see how you can get the children of a content node.
You can do all the things in your ApiController which you can do in a classic MVC Api Controller. If you need general informations about MVC Api Controller you can find here a beginner guide: http://www.asp.net/web-api/overview/getting-started-with-aspnet-web-api
Examples about JSON and XML Formatters: http://www.asp.net/web-api/overview/formats-and-model-binding/json-and-xml-serialization
Hope this helps?
Best, Sören
It worked perfectly! :) Thank you! I think the part I got confused about was that some methods didn't show up on ctrl + space.
Again, thx alot!
Hi Daniel,
great to hear this :-) If you have further questions, feel free and ask me or the friendly community again.
Cheers, Sören
is working on a reply...