Copied to clipboard

Flag this post as spam?

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


  • Nathan 67 posts 146 karma points
    Oct 22, 2014 @ 13:14
    Nathan
    0

    Get property values in utility class

    Hi,

    In Views I normally get my properties values like this:

    E.g.

    var myProperty = Umbraco.Content(3354).GetPropertyValue<ArchetypeModel>("myPropertyAlias");
    foreach(var item in myProperty)
    { <div>@item.GetValue("itemAlias")</div> }
    

    But how can I get my property values inside a utitilty class?

    Dan

  • Julio M. Vivas 61 posts 122 karma points
    Oct 22, 2014 @ 13:30
    Julio M. Vivas
    100

    I think that might be a job for the Umbraco helper

    var umbracoHelper = new Umbraco.Web.UmbracoHelper(Umbraco.Web.UmbracoContext.Current);
    

    Then you should be able to get access to properties as usual

    var myProperty = umbracoHelper.Content(3354).GetPropertyValue<ArchetypeModel>("myPropertyAlias");
    
  • Nathan 67 posts 146 karma points
    Oct 22, 2014 @ 14:14
    Nathan
    0

    Thanks Julio, works great!

    In my property I have an Media Picker data type, so I need to get the image url. Normally I would do:

    var img = Umbraco.TypedMedia(item.GetValue("icon"));
    <img src="@img.Url" />
    

    How can I get TypedMedia in my class?

    Thanks,

    Dan

  • Nathan 67 posts 146 karma points
    Oct 22, 2014 @ 14:36
    Nathan
    0

    Got this working using same "umbracoHelper":

    var image = umbracoHelper.TypedMedia(item.GetValue("icon"));
    

    Thanks!

    Dan

  • Julio M. Vivas 61 posts 122 karma points
    Oct 22, 2014 @ 15:13
    Julio M. Vivas
    0

    I was going to suggest exactly the same

    Glad you got it working

    J

Please Sign in or register to post replies

Write your reply to:

Draft