Copied to clipboard

Flag this post as spam?

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


  • Warren Harding 132 posts 275 karma points
    Mar 08, 2022 @ 04:39
    Warren Harding
    1

    Retreiving Dropdown Data Type Options

    Hi there, could anyone please advise how to pull in the prevalue options from a data type in v9?

    List<SelectListItem> listItems = new List<SelectListItem>();
    
    IDataTypeService dataTypeService = Current.Services.DataTypeService;
    
    var dataType = dataTypeService.GetDataType(DataTypeName);
    
    ValueListConfiguration prevalues = (ValueListConfiguration)dataType.Configuration;
    
    foreach (ValueListConfiguration.ValueListItem item in prevalues.Items)
    {
        listItems.Add(new SelectListItem { Value = item.Value, Text = item.Value, Selected = (ModelComparer == item.Value) });
    }
    

    I can't seem to get an ValueListConfiguration any longer in 9 as Umbraco.Core.PropertyEditors no longer exists?

    I'm trying to get this in a razor view, and have added

    @inject IDataTypeService DataTypeService
    

    So DataTypeService.GetDataType appears to be working correctly, but now I'm stuck.

    Thanks all!

  • Emily 6 posts 107 karma points
    May 25, 2022 @ 18:53
    Emily
    0

    Hi Warren,

    If you include a using for Umbraco.Cms.Core.PropertyEditors, you should be able to get it to work.

    Hope that helps!

Please Sign in or register to post replies

Write your reply to:

Draft