We have added nested content to our members to store data of variable length such as the names of their children.
I have made a surface controller in which a member can edit his/her profile and which also shows the nested content.
It is possible for me to edit and save the custom porperties of members, but I can't get the nested content to work.
I can fetch them in my GET-method and display them in my view, but I do not know how to save them in my POST-method.
Here is my simplified viewmodel:
public class MemberEdit : RenderModel
{
public int id { get; set; }
public string Firstname { get; set; }
public List <MemberNestedContent> Children { get; set; }
}
my GET
public ActionResult Index()
{
string memberId = Request.QueryString["id"];
IMember member = Services.MemberService.GetById(int.Parse(memberId));
IPublishedContent extendedMember = Umbraco.TypedMember(member.Id);
Member memberData = new Member(extendedMember);
MemberEdit memberEdit = new MemberEdit();
memberEdit.id = int.Parse(memberId);
memberEdit.Firstname = memberData.Firstname;
memberEdit.Children = new List<MemberNestedContent>();
foreach (IPublishedContent item in memberData.EmployeeChildren)
{
memberEdit.Children.Add(new MemberNestedContent(item));
}
return View(memberEdit);
}
and POST
public ActionResult Edit(MemberEdit memberEdit)
{
if (!ModelState.IsValid)
{
return View("Index", memberEdit);
}
IMember member = Services.MemberService.GetById(memberEdit.id);
member.SetValue("Firstname", memberEdit.Firstname);
// Save nested content???
Services.MemberService.Save(member);
return RedirectToCurrentUmbracoPage();
}
When I saw this topic appear last week it reminded me that I had a draft blog post in progress about exactly the same subject, saving Nested Content data for a member property.
Saving nested content of members
Hallo,
We have added nested content to our members to store data of variable length such as the names of their children. I have made a surface controller in which a member can edit his/her profile and which also shows the nested content. It is possible for me to edit and save the custom porperties of members, but I can't get the nested content to work. I can fetch them in my GET-method and display them in my view, but I do not know how to save them in my POST-method.
Here is my simplified viewmodel:
{ public int id { get; set; }
}
my GET
and POST
Nested content is just json data in a property.
Have a look at the following discussion: https://our.umbraco.org/projects/backoffice-extensions/nested-content/nested-content-feedback/72977-can-i-write-collection-of-ipublishedcontent-back-to-model-property
Thank you!
Your link guided me to this one as well: https://github.com/umco/umbraco-nested-content/issues/57
I got it all working using this information.
When I saw this topic appear last week it reminded me that I had a draft blog post in progress about exactly the same subject, saving Nested Content data for a member property.
I finally got round to finishing that blog post: http://codery.co.uk/blog/using-nested-content-to-store-member-data-in-umbraco/
As you can see it uses a slightly different approach with a strongly-typed model that gets (de)serialised from/to JSON.
is working on a reply...