Umbraco DataType which values are based from dictionary items. An alternative for creating custom doctype as datasource for your dropdowns, checkbox list or radio buttons.
- Checkbox List
- Radio Buttons
- Dropdown
Install from the developer section in Umbraco or download from the link below
https://our.umbraco.com/packages/backoffice-extensions/dictionary-type/
Install from NuGet package manager or run the following command in Visual Studio package manage console:
PM> Install-Package DictionaryType
- Create a parent dictionary item with it's children being the list items.
- Add the parent dictionary key name into the Parent Dictionary Key field in the Dictionary Property Editor.
- Add the created DataType into a DocumentType or MemberType and you'll have your child items as your choices in the list.
using DictionaryType.Foundation.Core.Helpers;
...
public class YourClass
{
private readonly IDictionaryTypeHelper _dictionaryHelper;
public YourClass(IDictionaryTypeHelper dictionaryHelper)
{
_dictionaryHelper = dictionaryHelper;
}
public List<SelectListItem> GetDictionaryList(string parentKey, string language = null)
{
var result = new List<SelectListItem>();
//Get the dictionary list
var dictionaryList = _dictionaryHelper.GetDictionaryList(parentKey, language);
if (dictionaryList != null && dictionaryList.Any())
{
result.AddRange(dictionaryList.Select(x => new SelectListItem() { Value = x.Key, Text = x.Value }));
}
return result;
}
}