Copied to clipboard

Flag this post as spam?

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


  • Hugo Migneron 32 posts 105 karma points
    Jul 31, 2014 @ 18:45
    Hugo Migneron
    0

    Dictionary Items in Razor

    Hi,

    Sorry about the simple question but I can't seem to figure it out by myself.

    The documentation (and a lot of forum posts) say that to use umbraco dictionary items I simply need to do 

    @Dictionary.MyItemKey

    I am trying to do just that in a partial view and I can't get it to compile / work. I probably have a missing @using directive, but which one? Where is the @Dictionary helper defined (i.e. what do I need to add to my cshtml file to make it work)? The following works fine, I am just trying to do it the dynamic way.

    @umbraco.library.GetDictionaryItem("MyItemKey")

    Thanks!

  • Dennis Aaen 4499 posts 18254 karma points admin hq c-trib
    Jul 31, 2014 @ 18:52
    Dennis Aaen
    0

    Hi Hugo,

    Have tried to do it this way?

    @Dictionary["MyItemKey"]

    Hope this helps,

    /Dennis

  • Hugo Migneron 32 posts 105 karma points
    Jul 31, 2014 @ 18:56
    Hugo Migneron
    0

    Yes I have actually and I still end up with errors when I run it (the same error I get with @Dictionary.MyItemKey : 

    Using the generic type 'System.Collections.Generic.Dictionary<TKey,TValue>' requires 2 type arguments

    So obviously there is something missing for the interpreter to make the difference between umbraco's dictionary helper and the normal System.Collections.Generic.Dictionary and this is what i'm looking for

    Thanks for you help,

    -Hugo


  • Dennis Aaen 4499 posts 18254 karma points admin hq c-trib
    Jul 31, 2014 @ 19:49
    Dennis Aaen
    102

    Hi Hugo,

    I have just seen the video on Umbraco TV about dictionary items, just to see how they suggest to work with dictionary items, and they are using this syntax.

    @Umbraco.GetDictionaryValue("MyItemKey")

    So when you are in MVC you need to use @Umbraco.GetDictionaryValue("MyItemKey") you can find the documentation here: http://our.umbraco.org/documentation/reference/Querying/UmbracoHelper/#GetDictionaryValue%28stringkey%29

    /Dennis

  • Hugo Migneron 32 posts 105 karma points
    Jul 31, 2014 @ 20:14
    Hugo Migneron
    0

    Hi Dennis,

    Thanks, it does work with the umbraco helper (@Umbraco.GetDictionaryValue) so I will go with that.

    I'm still curious as to how to get the @Dictionary helper though!

    Thanks again for your help

    -Hugo

  • Dennis Aaen 4499 posts 18254 karma points admin hq c-trib
    Jul 31, 2014 @ 20:25
    Dennis Aaen
    0

    Hi Hugo,

    That is great to hear, I am glad that I could help you out.

    In MVC @Umbraco (of type Umbraco.Web.UmbracoHelper) -> contains many helpful methods, from rendering macros and fields to retreiving content based on an Id and tons of other helpful methods. This is essentially the replacement for the 'library' object in the old codebase.

    Could you please mark the question as solved, so other that come across the question, can see what is worked for you.

    /Dennis

Please Sign in or register to post replies

Write your reply to:

Draft