Press Ctrl / CMD + C to copy this to your clipboard.
This post will be reported to the moderators as potential spam to be looked at
Hello. I am changing the value of some properties of the DropDownList editor in the database from C# code. My way works and everything is fine. Only here the property values remain the same until I restart the entire project. I understand that before the project is reloaded, it takes the value from the cache. How can I do it with a code so that after certain actions the cache is cleared?
Are you changing the properies on a contentnode? Can you show us a code example of what you are doing?
I really would caution against going directly to the DB and bypassing Umbraco's services - I know it's tempting because it is quicker, but caching is just one of the issues you will hit going this way.
Instead if you want to update a dropdown list, better to use the DataTypeService and alter the prevalues that way.
var item = _dataTypeService.GetDataTypeDefinitionByName("mydropdownlist");
var existingPreValues = _dataTypeService.GetPreValuesCollectionByDataTypeId(item.Id)
// existingPreValues is a list of alias, and value, so you can update it as needed
// then save them back
this will update the values in the db, and the cache.
Thank you so much Kevin for the tip. I want to try this way. But I am making a plugin and in my decision the name of editor will not be known in advance. Is there a function where I can take all the names and execute your decision for each editor?
Looks like I found. I used in my decision
var _dataTypeService = ApplicationContext.Current.Services.DataTypeService;
var editor = _dataTypeService.GetDataTypeDefinitionById(property.PropertyType.DataTypeDefinitionId);
var existingPreValues = _dataTypeService.GetPreValuesCollectionByDataTypeId(editor.Id)
Thanks again Kevin!
Kevin sorry again. I have implemented this solution, it works, only the problem remains. Until I restart the project, not all Prevalue are updated. What else should I try to do?
And another problem is that this solution only works with those PreValues of checkbox that are checked. Those PreValues that are but not selected, for some reason, it ignores :(
Ah OK, slightly crossed wires here.
From the last comment i think you are trying to change these values on a content item - except they are not actually stored against the content item.
So dropdown values (the text you see) are stored in the datatype, and you pick them from the content - the content stores the id of the item in the list (but it shows you the text on screen), so you can't actually change this on the content without changing it for everyone in the datatype (so all versions of the content using the drop down have their values changed)
I am assuming this is related to your language stuff of other posts ? if so then the answer for lists is not to actually translate them but use the umbraco dictionary to change the values.
One way i would look to achieve this on a site is to have dictionary item values that match the names in the dropdowns, and translate them on the page
so for example if we have a dropdown/checkbox list with the following
i would create dictionary items
then in the site code something like (this might be wrong syntax- just typing of the top of my head here)
var listvalue = Model.GetPropertyValue<string>("myListItem");
<div>@Umbraco.GetDictionaryItem("MyList." + listValue)</div>
Then the page will render the right value for the list from the dictionary, which means you haven't had to change a site wide value or mess about with hidden things.
You might be able to do this with dictionary values in the dropdown - for example if you call the value #MyList.MySecondValue then umbraco will show the translated text in the back office and return it - but to be honest i have not tried this with dropdown lists so i am not sure if it works like that.
is working on a reply...
Write your reply to:
Image will be uploaded when post is submitted