Copied to clipboard

Flag this post as spam?

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


  • Joseph Esquibel 7 posts 99 karma points
    Aug 25, 2015 @ 15:50
    Joseph Esquibel
    0

    What is the easiest way to get a selected dropdown prevalue as string?

    Hello All,

    I'm pretty new to Umbraco, and i'm loving it so far. I would love it even more if I knew how to get a selected value from a dropdown list.

    I was hoping I can pull the value in 1 line of code for my shorthand conditional statement, like so:

    enter image description here

    basically, if the prevalue "right" is selected, then I would float the div to the right.

    I read this article, which brought me a little closer, but no success: https://our.umbraco.org/documentation/getting-started/backoffice/property-editors/built-in-property-editors/dropdown-list-publishing-keys

    What am I doing wrong?

    Thanks in advance.

  • Christopher Pascual 27 posts 275 karma points
    Aug 26, 2015 @ 08:57
    Christopher Pascual
    0

    Hope this helps :

    <div class="col-md-4" @(sec.getProperty("Image Position").Value=="Right" ? "style='float:right'" : string.Empty)>
    
  • Joseph Esquibel 7 posts 99 karma points
    Aug 26, 2015 @ 14:37
    Joseph Esquibel
    0

    Thanks Christopher,

    I get a compilation error:

    CS1061: 'Umbraco.Core.Models.IPublishedContent' does not contain a definition for 'getProperty' and no extension method 'getProperty' accepting a first argument of type 'Umbraco.Core.Models.IPublishedContent' could be found (are you missing a using directive or an assembly reference?)

    I get past this error when I capitalized the "G" in GetProperty. Now I get an empty object error, not a definition error (I think this is good).

    I'll mess around with it today and let you know what I find.

    Everybody: please jump in if you think you know what the problem is.

    Thanks in advance.

  • MrFlo 159 posts 403 karma points
    Aug 26, 2015 @ 15:00
    MrFlo
    100

    It's may be better to check if you have the property as well with HasProperty:

    @(sec.HasProperty("imagePosition") && sec.GetProperty("imagePosition").Value=="Right" ? "style='float:right'" : string.Empty)
    

    Are you sure about your property name with a space ? This seems strange as when you create a property the alias is generated without space and in camel case...

  • Joseph Esquibel 7 posts 99 karma points
    Aug 26, 2015 @ 15:26
    Joseph Esquibel
    0

    MrFlo,

    That did it. Here's the the working code

    @(sec.GetProperty("imagePosition").Value.ToString() == "Right" ? "style=float:right" : string.Empty)
    

    Looks like I should have been using the alias rather than the property name. Thanks for your help!

Please Sign in or register to post replies

Write your reply to:

Draft