Copied to clipboard

Flag this post as spam?

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


  • Manish 373 posts 932 karma points
    Mar 07, 2017 @ 13:44
    Manish
    0

    Drop down values in razor

    Hi

    I have a dropdownlist with pre values in CMS. I want to get all items on a razor page.

    Thanks

  • Ravi Motha 290 posts 500 karma points MVP 8x c-trib
    Mar 07, 2017 @ 14:35
    Ravi Motha
    0

    Do yuo want to populate the drop down or or are you just trying to display a dropdownyou have set up in the back office??

  • Manish 373 posts 932 karma points
    Mar 08, 2017 @ 05:14
    Manish
    0

    Ravi thanks for your attention on problem

    I just wanted to show all values which is in CMS for drop down. I wanted to render all on my razor page.

    Manish

  • Dharmesh 50 posts 210 karma points
    Mar 08, 2017 @ 05:22
    Dharmesh
    100

    Hi Manish,

    You can do that in razor using this code:

    @{ var dataTypeId = umbraco.cms.businesslogic.datatype.DataTypeDefinition.GetAll().First(d => d.Text == "Dropdown").Id; var preValues = umbraco.cms.businesslogic.datatype.PreValues.GetPreValues(dataTypeId).Values; var enumerator = preValues.GetEnumerator();

    while (enumerator.MoveNext())
    {
        var preValueText = ((umbraco.cms.businesslogic.datatype.PreValue)enumerator.Current).Value;
        <option>@preValueText</option>
    }
    

    }

  • Manish 373 posts 932 karma points
    Mar 08, 2017 @ 08:47
    Manish
    0

    Thank you. Let me try with above one.

  • Manish 373 posts 932 karma points
    Mar 08, 2017 @ 09:09
    Manish
    0

    Thanks dharmesh it is working except one thing it is showing "Pre values is obsolate" as warning.

  • Ravi Motha 290 posts 500 karma points MVP 8x c-trib
    Mar 08, 2017 @ 09:26
    Ravi Motha
    1

    Hi Manish,

    I am preuming you are working in version 7.x so you may want to take the following approach to get those values

    This question and and answer should help you get what you want https://our.umbraco.org/forum/extending-umbraco-and-using-the-api/78280-get-pre-values-for-data-type

    Ravi

  • Manish 373 posts 932 karma points
    Mar 08, 2017 @ 09:33
    Manish
    0

    Yes I am using umbraco 7.x

  • This forum is in read-only mode while we transition to the new forum.

    You can continue this topic on the new forum by tapping the "Continue discussion" link below.

Please Sign in or register to post replies