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);
}
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);
Refresh datatypes on save
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
Pre Value controller read:
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.
is working on a reply...