Copied to clipboard

Flag this post as spam?

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


  • Anthony Candaele 1197 posts 2049 karma points
    Nov 02, 2012 @ 16:00
    Anthony Candaele
    0

    access Dictionary Items with Razor

    Hi,

    How can I access the value of a Dictionary Item from within a Razor script (.cshtml)?

    Thanks for your help,

    Anthony

  • Jan Skovgaard 11280 posts 23678 karma points MVP 10x admin c-trib
    Nov 02, 2012 @ 16:40
    Jan Skovgaard
    3

    Hi Anthony

    It actually seems it's covered a little bit in the Razor Cheat Sheet in the lower left section named "Dictionary".

    Hope this helps :)

    /Jan

  • Anthony Candaele 1197 posts 2049 karma points
    Nov 02, 2012 @ 17:18
    Anthony Candaele
    1

    Hi Jan,

    ... having to get Razor help from the Xslt Rebel Alliance, this is a total embarrasment :)

    Thanks for the tip.

    Sebastian (@Cultiv) also gave me some help. Dictionary Items can be accessed in Razor script using the umbraco.library.GetDictionaryItem("DictionaryItem")

    This works great me.

    Jeavon Leopold (@crumpled_jeavon) pointed me to and example using the Dictionary Picker in Razor

     

    greetings,

    Anthony

  • Anthony Candaele 1197 posts 2049 karma points
    Nov 02, 2012 @ 18:20
    Anthony Candaele
    0

    I checked the Razor DynamicNode Cheatsheet, this code does the job:

    @Dictionary["dictionaryItemAlias"]

    greetings,

    Anthony

  • Jan Skovgaard 11280 posts 23678 karma points MVP 10x admin c-trib
    Nov 02, 2012 @ 18:36
    Jan Skovgaard
    1

    Hi Anthony

    I'm just happy I was able to help you out so you can make awesomeness in Umbraco :)

    Have fun mate.

    /Jan

  • Anthony Candaele 1197 posts 2049 karma points
    Nov 12, 2012 @ 09:15
    Anthony Candaele
    0

    FYI the Umbraco Documentation has now documentation on using Dictionary Items in Razor

    greetings,
    Anthony

  • Brett Spencer 88 posts 259 karma points
    Dec 29, 2015 @ 18:34
    Brett Spencer
    2

    The cheat sheet still needs some updates. Yes, you can find it in the documentation...

    Since this IS documentation...

    As of 7.x, you can use

    @{
         Umbraco.Field("#DictionaryTerm");
     }
    

    I just used this today:

       @{
            var download = Umbraco.Field(#Download").ToString();  // call ToString() otherwise it is IHtmlString
        }
        <span class="button">@download</span>
    

    //** Almost 3 years later... I am working on a partial view that only inherits a custom view model and couldn't use Umbraco.Field. So in that scenario, this is what to use:

    @umbraco.Library.GetDictionaryItem("Download")
    
Please Sign in or register to post replies

Write your reply to:

Draft