Copied to clipboard

Flag this post as spam?

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


  • SuperSixBravo 1 post 71 karma points
    May 26, 2020 @ 15:29
    SuperSixBravo
    0

    Register Member Member Properties not saving.

    Hi all, I am new to Umbraco and fairly new to MVC. Loving Umbraco but I am very stuck on creating a member.

    I am using the register member snippet, I have added some A title & First name / surname to my member type. The Title value will not save from the drop down list no matter what I do. I have made a custom editor as per the comments in the snippet.

    Custom Editor Code:

    @using System.Collections @using Umbraco.Core; @using Umbraco.Core.Composing.CompositionExtensions @using Umbraco.Core.Models; @using Umbraco.Core.Services; @using Umbraco.Core.Services; @using Umbraco.Core.PropertyEditors; @using Umbraco.Core.Services.Implement @using Umbraco.Forms.Core.Providers.FieldTypes

    @{

    IDataTypeService dataTypeService = Umbraco.Core.Composing.Current.Services.DataTypeService;
    // Change number to id of your custom values (We should change this to get them by name and wrap it in to a class)
    IDataType dataType = dataTypeService.GetDataType(1119);
    ValueListConfiguration preValues = (ValueListConfiguration)dataType.Configuration;
    
    List<SelectListItem> items = new List<SelectListItem>();
    
    
    foreach (ValueListConfiguration.ValueListItem item in preValues.Items)
    {
    
        items.Add(new SelectListItem { Text = Convert.ToString(item.Value), Value = Convert.ToString(item.Id) });
    
    }
    

    }

    @* @{

    foreach (ValueListConfiguration.ValueListItem item in preValues.Items)
    {
        <option value="@Convert.ToString(item.Id)">@item.Value</option>
    }
    

    } @**@

    And here is the main signup view

              @if (registerModel.MemberProperties != null)
            {
                @*
                    It will only displays properties marked as "Member can edit" on the "Info" tab of the Member Type.
                *@
                for (var i = 0; i < registerModel.MemberProperties.Count; i++)
                {
                    @Html.LabelFor(m => registerModel.MemberProperties[i].Value, registerModel.MemberProperties[i].Name)
                    @Html.HiddenFor(m => registerModel.MemberProperties[i].Alias)
                    @*
                        By default this will render a textbox but if you want to change the editor template for this property you can
                        easily change it. For example, if you wanted to render a custom editor for this field called "MyEditor" you would
                        create a file at ~/Views/Shared/EditorTemplates/MyEditor.cshtml", then you will change the next line of code to
                        render your specific editor template like:
                        @Html.EditorFor(m => registerModel.MemberProperties[i].Value, "MyEditor")
                    *@
    
                    if (registerModel.MemberProperties[i].Alias == "title")
                    {
                        @Html.EditorFor(m => registerModel.MemberProperties[i].Value, "MemberTitleSelect", new { id = registerModel.MemberProperties[i].Value })
                        @Html.HiddenFor(m => registerModel.MemberProperties[i].Alias)
    
    
                    }
                    else
                    {
                        @Html.EditorFor(m => registerModel.MemberProperties[i].Value)
                        @Html.HiddenFor(m => registerModel.MemberProperties[i].Alias)
                    }
    
                    <br />
                }
            }
    
            @Html.HiddenFor(m => registerModel.MemberTypeAlias)
            @Html.HiddenFor(m => registerModel.RedirectUrl)
            @Html.HiddenFor(m => registerModel.UsernameIsEmail)
    
            <button>Register</button>
        </fieldset>
    }
    

    Can anybody please help me? everything saves apart from the dropdown list, sometimes after testing it, I cant load the members module in the umbraco back office because it errors saying it convert string to int, I have tried various combinations. Of course if I create the member in umbraco it saves the title.

    Any help would be greatly appreciated

    EDIT** The Select box is being messed up by the Forum it should look like this.

    @*

  • Steve Morgan 1117 posts 3535 karma points c-trib
    May 28, 2020 @ 11:21
    Steve Morgan
    0

    hi,

    I've got this working but it's a complete hackfest. You're using an ancient macro partial - I strongly suggest you create a proper controller and partial view and do this a more MVC way. You should check the values that are submitted are of the right type and sanitised. Whilst hacking around I was submitting the wrong data format and broke the member back end which is really not good.

    I think the problem is you need to create a select box with the name and id so that it binds to the correct field in the database and we need to have it in the format (a property converter needs to fire - we need to store ["Mr"] not 1 or Mr

    I've hacked a solution - it works but... I'm really not keen to post it here as someone will use it and I can see a security issue in it. I really think you need to go down a proper MemberRegisterController with models and proper binding.

    Steve

Please Sign in or register to post replies

Write your reply to:

Draft