Copied to clipboard

Flag this post as spam?

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


  • Anders Brännmark 220 posts 250 karma points
    Nov 07, 2017 @ 15:08
    Anders Brännmark
    1

    UDI and ContentService / GetValue<>

    Using the contentpicker2 with the UDI. Need to grab the selected content item in an eventhandler with ContentService or IContent.GetValue<> but there doesnt seam to any propertyvalueconverters or methods that can use the UDI that is stored.

    Or?

  • Kevin Jump 1789 posts 11535 karma points MVP 4x c-trib
    Nov 07, 2017 @ 18:34
    Kevin Jump
    2

    Hi

    ideally for front end stuff you should use the Umbraco.TypedContent helpers as this gets stuff from the cache. where you can pass the UDI directly

    var item = Umbraco.TypedContent(myUdi);
    

    however - if you do need the backoffice content:

    you can get a number of uid's with

    var items = Services.ContentService.GetByIds(new List<Udi> { myUdi } )
    

    but that returns a list of multiple items; If you just want one, then there isn't a direct function - you can get the GUID from the UDI and call that.

    var guidUdi = myUdi as GuidUdi;
    if (guidUdi != null)
    {
        var item = Services.ContentService.GetById(guidUdi.Guid);
    }
    

    This turns the Udi into a GuidUdi and then lets you directly get the Guid - ideally you would also check this is infact a content Udi before you did this - but it hopefully shows you how you might do it.

Please Sign in or register to post replies

Write your reply to:

Draft