Copied to clipboard

Flag this post as spam?

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


  • Benjamin Stengaard 27 posts 141 karma points
    Nov 07, 2017 @ 14:26
    Benjamin Stengaard
    0

    Umbraco 7.7.4, Dropdown list multiple returns wrong string

    When i'm using Dropdown list multiple (typed used inside a loop of products) It does not return the string values like the documentation tells: https://our.umbraco.org/Documentation/Getting-Started/Backoffice/Property-Editors/Built-in-Property-Editors/DropDown-List-Multiple

    It returns: System.Linq.Enumerable+WhereSelectArrayIterator`2[System.String,System.String]

    Can anyone tell me how i get the selected values?

  • Matt Darby 28 posts 391 karma points c-trib
    Nov 07, 2017 @ 15:18
    Matt Darby
    101

    Hi Ben,

    You're right, the sample is incorrect.

    Try this:

            if (Model.Content.HasValue("testDropdown"))
            {
                <ul>
    
                    @foreach (var item in Model.Content.GetPropertyValue<IEnumerable<string>>("testDropdown"))
                    {
                        <li>@item</li>
                    }
                </ul>
            }
    

    If you are using the models builder, it is simply:

                    @foreach (var item in Model.Content.TestDropdown)
                    {
                        <li>@item</li>
                    }
    
  • Benjamin Stengaard 27 posts 141 karma points
    Nov 07, 2017 @ 15:30
    Benjamin Stengaard
    0

    Hi Matt

    That did the trick, thanks :)

Please Sign in or register to post replies

Write your reply to:

Draft