Copied to clipboard

Flag this post as spam?

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


  • Lesley 93 posts 333 karma points
    Apr 04, 2018 @ 04:42
    Lesley
    0

    Custom checkbox list properties for Members

    I have added some custom properties to the default Member Type of Member.

    Some of these custom properties are custom Checkbox List data types.

    I'm able to successfully create new members and populates these fields.

    I now need to create a razor-based Edit Profile page on the website to allow users to update their profile.

    How do I create the custom Checkbox List properties on this page?

    Members.GetCurrentMemberProfileModel() only returns the selected value for these properties. There is no information regarding the data type that the property belongs to.

    Am I going to have to hard-code the data type ids for the custom properties on the Edit Profile page?

  • Andrew Hopkins 1 post 71 karma points
    Jul 12, 2018 @ 13:48
    Andrew Hopkins
    0

    I'm having the same issue, cannot find any documentation on this at all.

  • Lesley 93 posts 333 karma points
    Jul 12, 2018 @ 20:34
    Lesley
    0

    This is what I ended up doing, gender and communication method are my custom checkbox lists

    Created an EditMemberViewModel:

        /// <summary>
    /// Edit Member View Model
    /// </summary>
    public class EditMemberViewModel
    {
        public ProfileModel Member { get; set; }
    
        public IEnumerable<SelectListItem> Gender { get; set; }
        public IEnumerable<SelectListItem> CommunicationMethod { get; set; }
    }
    

    I then created a SurfaceController with an EditMember method:

        public class AuthSurfaceController : SurfaceController
    

    .... .... .... ...

            public ActionResult EditMember()
        {
            var model = new EditMemberViewModel
            {
                // This returns the editable fields so doesn't include FirstName, LastName, DateOfBirth or MembershipType
                Member = Members.GetCurrentMemberProfileModel(),
            };
    
    
            // Get lookup values
            model.Gender = GetPrevalues("Member - Gender - Checkbox list", model.Member.MemberProperties, "gender");
            model.CommunicationMethod = GetPrevalues("Member - Communication Method - Checkbox list", model.Member.MemberProperties, "communicationMethod");
    
            return PartialView("Membership/EditMember", model);
        }
    

    Then in my EditMember razor view at the top:

        var profileModel = Model.Member;
    

    and then further down this snippet of code renders radiobuttons for the custom checkbox fields

                                            @if (textArea.Contains(alias))
                                        {
                                            @Html.TextAreaFor(m => profileModel.MemberProperties[i].Value)
                                        }
                                        else if (alias == "gender")
                                        {
                                            foreach (var item in Model.Gender)
                                            {
                                                <div>
                                                    @Html.RadioButtonFor(m => profileModel.MemberProperties[i].Value, item.Value)
                                                    @Html.Label(item.Text)
                                                </div>
                                            }
    
                                        }
                                        else if (alias == "communicationMethod")
                                        {
                                            foreach (var item in Model.CommunicationMethod)
                                            {
                                                <div>
                                                    @Html.RadioButtonFor(m => profileModel.MemberProperties[i].Value, item.Value)
                                                    @Html.Label(item.Text)
                                                </div>
                                            }
    
                                        }
                                        else
                                        {
                                            @Html.EditorFor(m => profileModel.MemberProperties[i].Value)
                                        }
    

    Hope that helps. Let me know if you need any more info..

Please Sign in or register to post replies

Write your reply to:

Draft