Copied to clipboard

Flag this post as spam?

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


  • Aaron 20 posts 180 karma points
    Aug 15, 2018 @ 14:01
    Aaron
    0

    I have a dropdown datatype which i add to / delete from within the front end on save.

    So for example when a company is created on the front end it saves the name and id into a datatype within umbraco, this is then loaded on a create job page so that the user can select the company from a drop down.

    I have the code adding it into the prevalues list, however it needs to have the modelbuilder regenerated before it will show the new option in the drop down.

    How can i get it to refresh the datatype on save, so that it updates the dropdown instantly rather than requiring a manual modelbuilder regeneration.

    Prevalue insert code

                Dictionary<string, PreValue> updatedPreValues = new Dictionary<string, PreValue>();
            var preValues = Services.DataTypeService.GetPreValuesCollectionByDataTypeId(1384).PreValuesAsDictionary;
            if (preValues.Any())
            {
                foreach (var preValue in preValues.Where(pv => !pv.Value.Value.Contains(companyDisplayName)))
                {
                    updatedPreValues.Add(preValue.Key, preValue.Value);
                }
            }
            Services.DataTypeService.SavePreValues(1384, updatedPreValues);
    

    Pre Value controller read:

        private SelectList GetSelectListForCompanies()
        {
            var preValueDataType = Umbraco.DataTypeService.GetPreValuesCollectionByDataTypeId(1384);
            var preValues = preValueDataType.PreValuesAsDictionary.Values.Where(pdv => pdv.Value != "0");
    
            var companiesList = preValues.Select(preValue => new SelectListItem
                {
                    Value = preValue.Id.ToString(),
                    Text = preValue.Value
                })
                .ToList();
    
            companiesList.Insert(0, new SelectListItem()
            {
                Text = "Company",
                Value = "0",
                Selected = true,
                Disabled = true
            });
    
            return new SelectList(companiesList);
        }
    
  • Stuart Mullinger 62 posts 288 karma points
    Apr 16, 2020 @ 14:52
    Stuart Mullinger
    0

    I realise that this is an old question, but in case it helps anyone who lands here after a search (as I did), I found that saving the datatype itself fixed this issue for me.

    var dataType = Services.DataTypeService.GetDataTypeDefinitionById(guid);
    Services.DataTypeService.Save(dataType, currentUserId);
    
Please Sign in or register to post replies

Write your reply to:

Draft