Copied to clipboard

Flag this post as spam?

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


  • Rob Watkins 369 posts 701 karma points
    Aug 03, 2023 @ 12:27
    Rob Watkins
    0

    Get member property description to display in RegisterMember macro

    Got the registration all working perfectly, but I want to display the description for a custom member property on the form as help text; I can't see a way of doing that as the MemberPropertyModel doesn't have much on it?

    <div class="register-field">
        @Html.LabelFor(m => registerModel.MemberProperties[i].Value, registerModel.MemberProperties[i].Name)
        **@registerModel.MemberProperties[i].Description**  THIS BIT DOESN'T WORK
        <input asp-for="@registerModel.MemberProperties[i].Value" class="form-control" />
        @Html.HiddenFor(m => registerModel.MemberProperties[i].Alias)
        <span asp-validation-for="@registerModel.MemberProperties[i].Value" class="form-text text-danger"></span>
    </div>
    
  • Huw Reddick 1929 posts 6717 karma points MVP 2x c-trib
    Aug 03, 2023 @ 14:46
    Huw Reddick
    1

    Hi Rob,

    You could inject the IMemberTypeService and do the following

                    var membertype = memberTypeService.Get("YOURMEMBERTYPEALIAS");
                    var desc = membertype.PropertyTypes.First(p => p.Alias == "propertyAlias").Description;
    
  • Huw Reddick 1929 posts 6717 karma points MVP 2x c-trib
    Aug 03, 2023 @ 14:49
    Huw Reddick
    100

    personally I wouldn't do this :)

    I would add a string to the dictionary and use that, the property descriptions are really meant for telling back office users about the property rather than displaying in the front-end

  • Rob Watkins 369 posts 701 karma points
    Aug 03, 2023 @ 15:11
    Rob Watkins
    0

    Great, thanks! That works. Went to Translation, created a dictionary item to identify the string by the property type alias (e.g. Help/Registration/nickname) and add this to the loop that gets the custom properties:

    string help = Umbraco.GetDictionaryValue("Help/Registration/" +  registerModel.MemberProperties[i].Name);
    
        if(!String.IsNullOrWhiteSpace(help))
        {
            <div class="register-help">
               @help
            </div>
        }
    
  • Huw Reddick 1929 posts 6717 karma points MVP 2x c-trib
    Aug 03, 2023 @ 15:43
    Huw Reddick
    0

    Exactly what I do :)

Please Sign in or register to post replies

Write your reply to:

Draft