Copied to clipboard

Flag this post as spam?

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


  • Rohan 105 posts 162 karma points
    May 26, 2015 @ 09:56
    Rohan
    0

    how to get Umbraco dropdown list datatype values on cshtml page?

    Hi

    I am using Umbraco 7.2.0.

    I have the requirement to add Dropdown list datatype on Umbraco Content page with values and then need to check / compare the values / text  of that dropdown on front website (cshtml) pages and need to do some operations.

    Right now i am able to add the value to the dropdown list but don't know how to get the Selected Value / Text on cshtml page ?

    Can anyone please help me here ?

    thanks

    rohan dave

     

  • Urvish 252 posts 776 karma points
    May 26, 2015 @ 10:38
    Urvish
    0

    Hi Rohan,

    You can get data type Dropdown list value in Razor using below code.

    @{    
        var prevalues = umbraco.library.GetPreValues(1245);
     }
    

    you can perform whatever operation you want using above varible.

    Or else you can refer below link.

    https://our.umbraco.org/wiki/reference/umbracolibrary/getprevalues

    Hope this will help you.

    Regards,

    Urvish Mandaliya

  • Urvish 252 posts 776 karma points
    May 26, 2015 @ 10:43
    Urvish
    1

    And also you can use DataTypeService to get values.

    @{
        Umbraco.Core.Services.DataTypeService serviceData = new Umbraco.Core.Services.DataTypeService();
        var prevalues =  serviceData .GetPreValuesByDataTypeId(1245);   // 1245 = Data type Id
     }
    

    Then you can get drop down list selected value using javascript.

  • Dennis Aaen 4500 posts 18255 karma points admin hq c-trib
    May 26, 2015 @ 10:50
    Dennis Aaen
    1

    Hi Rohan,

    You can get the selected value from the current page you can use this Razor if you are using Dynamic Razor.

    @if (CurrentPage.HasValue("superHero"))
    {
        <p>@CurrentPage.superHero</p>
    }  
    

    If you are using strong typed then I has to look this this.

    @if (Model.Content.HasValue("superHero"))
    {
        <p>@Model.Content.GetPropertyValue("superHero")</p>
    }
    

    You can find the documentation about how to work with the dropdown list here: https://our.umbraco.org/documentation/using-umbraco/backoffice-overview/property-editors/Built-in-Property-Editors-v7/DropDown-List

    Hope this helps,

    /Dennis

  • 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