Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at


  • Frans Lammers 34 posts 297 karma points c-trib
    Dec 08, 2016 @ 10:12
    Frans Lammers
    0

    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 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();
        }
    
  • Sven Geusens 161 posts 869 karma points c-trib
    Dec 08, 2016 @ 14:49
  • Frans Lammers 34 posts 297 karma points c-trib
    Dec 12, 2016 @ 15:05
    Frans Lammers
    0

    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.

  • Tom van Enckevort 100 posts 387 karma points
    Dec 16, 2016 @ 22:13
    Tom van Enckevort
    1

    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.

Please Sign in or register to post replies

Write your reply to:

Draft