I did it your way and it works fine when adding and in the backoffice the values are added,
but when I retrieve the value to show it on my website I got this error
can you help me to solve this error?
I am having almost the same code as that @Alex has advice.
var cs = Services.ContentService;
var Parent = cs.GetById(Convert.ToInt32(NodeId));
var uLikes = new List<Dictionary<string, string>>();
uLikes.Add(new Dictionary<string, string>() {
{"ncContentTypeAlias","userPost"},
{"key", new Guid.NewGuid().ToString() },
{"mUser", UserGUID().ToString()}, // get Members ID
});
Parent.SetValue("post", Newtonsoft.Json.JsonConvert.SerializeObject(uLikes));
cs.SaveAndPublish(Parent);
But the issue is every time it overwrites the Old Value with the new one.
As I need to append/add new Items to nested content!
How can I add an item to nested-content (IEnumerable<IPublishedElement>>("usps")) programmatically?
I have
usps
nested-content property on-page and I want to add a new item tousps
list from backendThe item property name is
usp
Thanks in advance.
Hi Davit,
Something like:
Thanks,
Alex
Hi Alex
I did it your way and it works fine when adding and in the backoffice the values are added, but when I retrieve the value to show it on my website I got this error can you help me to solve this error?
Hi Alex, I am new to Umbraco. How do I get node in your example. Currently i am using umbraco 8.8 . Can you please suggest me. .
Alex thank you very much it works perfectly.
Thanks David
I am having almost the same code as that @Alex has advice.
But the issue is every time it overwrites the Old Value with the new one. As I need to append/add new Items to nested content!
so how can I do so?
Thanks
BJ
You are creating a new
uLikes
object every time and saving it.You need to get the existing
uLikes
object, deserialize it, add your new Dictionary item, and then save this updateduLikes
value.is working on a reply...