Copied to clipboard

Flag this post as spam?

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


  • Josip 195 posts 662 karma points c-trib
    Sep 11, 2018 @ 19:27
    Josip
    0

    How to get child item ID

    I cant find the way to get child item ID in my foreach loop, which i use for accordion. I want to do this because each accordion must have diferent ID because of collapse. If i use this @Umbraco.Field("pageID") , i got ID from parent page. And i want id from each list item in parent page. This is my code:

    <section class="container">
        <h3>Opis pojedinačnih sustava veza</h3>
        <div class="panel-group" id="accordion">
    
            @{
                var selection = Model.Content.Site().FirstChild("mototrboSistems").Children("mototrboItems").Where(x => x.IsVisible());
            }
            @foreach (var item in selection)
            {
    
                <div class="panel panel-default">
                    <div class="panel-heading" data-toggle="collapse" data-parent="#@Umbraco.Field("pageID")" href="#1">
                        <h4 class="panel-title">
                            @item.Name
                        </h4>
                    </div>
                    <div id="@Umbraco.Field("pageID")" class="panel-collapse collapse">
                        <div class="panel-body">
                            <div class="row">
                                <div class="col-sm-10">
                                    <h4>@item.GetPropertyValue("subtitle")</h4>
                                    <p>
                                        @item.GetPropertyValue("textBody")
                                    </p>
                                </div>
                                <div class="col-sm-2">
                                    <img class="img-responsive" src="~/Images/direktanNacin.png" />
                                </div>
                            </div>
                            <div class="row">
                                <div class="col-sm-10">
                                    <h4>Podržavaju sljedeće radio stanice:</h4>
                                    <p>
                                        @item.GetPropertyValue("podrzaneRadioStanice")
                                    </p>
                                </div>
                                <div class="col-sm-2">
                                    <h4>Dimenzije</h4>
                                    <p>
                                        @item.GetPropertyValue("dimensions")
                                    </p>
                                </div>
                            </div>
                        </div>
                    </div>
                </div>
            }
        </div>
    </section>
    
  • Blake Watt (Clerke) 106 posts 351 karma points MVP
    Sep 11, 2018 @ 20:19
    Blake Watt (Clerke)
    100

    Hi!

    In your foreach loop did you try @item.Id ? That should return the Id of the item for you (replacing your @Umbraco.Field("pageID"))

    Hope that helps! :)

  • Josip 195 posts 662 karma points c-trib
    Sep 11, 2018 @ 20:52
    Josip
    0

    Thank you, IT WORKS, but i swear that i alredy tried it and it didnt work :P

Please Sign in or register to post replies

Write your reply to:

Draft