Copied to clipboard

Flag this post as spam?

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


  • Yves Kircher 21 posts 69 karma points
    Oct 09, 2014 @ 11:33
    Yves Kircher
    0

    Get ID of a DataType By its Alias

    Hey,

    how do i get a DataType ID by its Alias in Razor?

    i need this to get the prevalues of a Datatype with GetPreValuesByDataTypeId(xxx)

    Alternatively:
    I have the node of a page of my side that belongs to a datatype, how can i get the prevalues of this datatype?
    (the datatype is created manually by me )

     

     

  • Ali Sheikh Taheri 470 posts 1648 karma points c-trib
    Oct 09, 2014 @ 12:02
    Ali Sheikh Taheri
    0

    Hi yves

    What version of Umbraco are you using?

    Cheers

    Ali

  • Yves Kircher 21 posts 69 karma points
    Oct 09, 2014 @ 12:03
    Yves Kircher
    0

    i am using v7.1.6

  • Phil 54 posts 139 karma points
    Oct 24, 2014 @ 11:10
    Phil
    1

    @Yves

    I have got the following code running in 7.1.8:

    var dataTypeService = ApplicationContext.Current.Services.DataTypeService;
    var allTypes = dataTypeService.GetAllDataTypeDefinitions();
    
    //Replace Data Type Name with the name of the required datatype
    var typeId = allTypes.First(x => "Data Type Name".InvariantEquals(x.Name)).Id;
    

    If you are trying to get the prevalues of your data type, the following can be used:

    var values = dataTypeService.GetPreValuesByDataTypeId(typeId);
    

    Good luck!

Please Sign in or register to post replies

Write your reply to:

Draft