Copied to clipboard

Flag this post as spam?

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


  • How Do I Delete My Account? 68 posts 433 karma points
    Jul 10, 2015 @ 01:43
    How Do I Delete My Account?
    0

    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

  • Sören Deger 729 posts 2838 karma points c-trib
    Jul 10, 2015 @ 03:23
    Sören Deger
    0

    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

  • How Do I Delete My Account? 68 posts 433 karma points
    Jul 12, 2015 @ 23:56
    How Do I Delete My Account?
    0

    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!

  • Sören Deger 729 posts 2838 karma points c-trib
    Jul 13, 2015 @ 06:02
    Sören Deger
    100

    Hi Daniel,

    please have a look to the first example in the link:

    @{
        var page = Umbraco.Content(1234);
    }
    
    <h3>@page.PropertyAlias</h3>
    
    @foreach (var child in page.Children) { 
        <a href="@child.Url">@child.Name</a>
    }
    

    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

  • How Do I Delete My Account? 68 posts 433 karma points
    Jul 13, 2015 @ 12:25
    How Do I Delete My Account?
    0

    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!

  • Sören Deger 729 posts 2838 karma points c-trib
    Jul 13, 2015 @ 12:30
    Sören Deger
    0

    Hi Daniel,

    great to hear this :-) If you have further questions, feel free and ask me or the friendly community again.

    Cheers, Sören

Please Sign in or register to post replies

Write your reply to:

Draft