Copied to clipboard

Flag this post as spam?

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


  • philip knight 9 posts 30 karma points
    Dec 01, 2023 @ 21:31
    philip knight
    0

    How to get the prevalues from a dropdown

    Hello all,

    I have a dropdown datatype and I'm trying to pull all of the prevalues into my Razor page. I'm new to dotnet and everything I've tried makes my site explode. Any help would be appreciated.

    Thanks

  • Johannes Lantz 156 posts 839 karma points c-trib
    Dec 04, 2023 @ 16:26
    Johannes Lantz
    1

    Hello Philip!

    I belive you could use IDataTypeValueService. Inject it into your razor view by doing this:

    @inject IDataTypeValueService _dataTypeValueService;
    

    Then you could use it like this:

    _dataTypeValueService.GetItemsFromValueListDataType("dataTypeAlias", null);
    

    I hope this helps you get on the right track!

    //Johannes

  • philip knight 9 posts 30 karma points
    Dec 05, 2023 @ 19:10
    philip knight
    1

    thank you Johannes.

    Is there a @using statement I should include? When I inject IDataTypeValueService into my razor page, it breaks with teh error: The type or namespace name 'IDataTypeService' could not be found (are you missing a using directive or an assembly reference?)

    Thanks again

  • Danine Noble 82 posts 368 karma points
    Dec 05, 2023 @ 19:36
    Danine Noble
    1

    For default Umbraco I can only find details on a 'DataTypeService' not a Value service, but perhaps it's what was meant? Handy to know where this sort of thing is in the documentation either way :3 It shows the usings needed for views.

    The only mention of a DataTypeValueService I can find is a custom service in a tutorial for v8 done by Paul Seal.

  • Johannes Lantz 156 posts 839 karma points c-trib
    Dec 05, 2023 @ 19:36
    Johannes Lantz
    0

    Ah! Sorry, I was a bit quick there!

    Yes!

    @using Umbraco.Cms.Core.Services;
    @using Umbraco.Cms.Core.PropertyEditors;
    

    Then you can do

    var dataTypeConfig = (ValueListConfiguration)_dataTypeValueService.GetDataType("dataTypeName").Configuration;
    

    //Johannes

  • philip knight 9 posts 30 karma points
    Dec 05, 2023 @ 21:27
    philip knight
    0

    Good deal. Thank you both!

Please Sign in or register to post replies

Write your reply to:

Draft