Try our conversational search powered by Generative AI!
AI OnAI Off
Aug 26, 2015
Oct 27, 2016
CMS Core
Closed, Fixed and tested
The following code does not save categories to the database:
var content = ContentRepository.GetDefault<StandardPage>(ContentReference.StartPage); content.Name = "Category test"; content.Category = new CategoryList(new[] { 2 })*; // Where a category with ID 2 exist. contentRepository.Save(content, SaveAction.Publish);
But this one does:
var content = ContentRepository.GetDefault<StandardPage>(ContentReference.StartPage); content.Name = "Category test"; content.Category.Add(2); contentRepository.Save(content, SaveAction.Publish);
The problem is that a CategoryList (where values are set in the constructor) is not considered modified, and this means that we do not save the values either.
The underlying PropertyData object will, in both cases, be considered modified if checked after the Category is modified.
content.Property[MetaDataProperties.PageCategory].IsModified == true;