Copied to clipboard

Flag this post as spam?

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


  • Luke 110 posts 256 karma points
    Sep 16, 2014 @ 15:36
    Luke
    0

    Rendering The Correct Property Editor (Frontend)

    I am new to Umbraco - so excuse my ignorance if this is a silly question!

    I want my Members to be able to update their profiles. There is quite a few properties for them to edit. I have created a partial view to do this, however I can not work out how to render the correct property editor for the associated property.

    The default - for example - @Html.EditorFor(m => profileModel.MemberProperties[i].Value) simply renders a textbox, whether it is a TRUE/FALSE datatype or RADIO BUTTON LIST datatype or some other data type.

    I have been playing around with @umbraco.cms.businesslogic.datatype.DataTypeDefinition.GetAll().First(d=> d.Id == prop.DataTypeDefinitionId).DataType.PrevalueEditor.Editor

    Please can somebody help me to render the correct property editor? Thanks in advance!

  • Jeavon Leopold 3072 posts 13628 karma points MVP 10x admin c-trib
    Sep 19, 2014 @ 15:37
    Jeavon Leopold
    1

    Hi There,

    You should be looking at using the "ProfileModel" that you can access from the MemberShipHelper. I was sure I had seen a tutorial or walk through but typically I can't seem to locate it now, I will keep looking...

    Jeavon

  • Charles Afford 1163 posts 1709 karma points
    Sep 20, 2014 @ 16:53
    Charles Afford
    0

    Hi L,

    What are you trying to render?

    What type is profileModel.MemberProperties[i].Value

    What other properties do you have in ProfileModel?

    Charlie :)

  • Luke 110 posts 256 karma points
    Oct 22, 2014 @ 11:30
    Luke
    0

    Hi Charlie,

    Sorry for the very late reply, but wanted to reply so as not be rude. The ProfileModel consists of many different properties some simple and some custom data types.

    In the end - I applied a switch statement to see the data type of each property.

    Thank you also Jeavon for your help!

    Thank you for your help and again apologies for late reply!

  • Scott Devine 8 posts 73 karma points
    Jun 15, 2015 @ 02:15
    Scott Devine
    0

    Hi am using a switch statement and getting the alias of the property then trying to render an appropriate control

    I have tried to use @Html.CheckBoxFor(m => profileModel.MemberProperties[i].Value)

    but get the error - Cannot implicitly convert type 'string' to 'bool'

    Has anyone got this working?

  • Luke 110 posts 256 karma points
    Jun 15, 2015 @ 08:39
    Luke
    0

    Hi Scott,

    I did get something working - although it was not easy easy.

    I created an editor for each control. By default when you use:

    @Html.EditorFor(m => profileModel.MemberProperties[p].Value, ctrlType, new { CurrentProperty = profileModel.MemberProperties[p], CurrentPropertyType = prop, Extras = ExtrasObj })
    

    The framework will look in ~/Views/Shared/EditorTemplates directory.

    The razor code looks a little like this:

    var type = ApplicationContext.Current.Services.MemberTypeService.Get(mt);
                    @foreach (var tab in type.CompositionPropertyGroups)
                    {                                       
                        bool TabRendered = false;
                        foreach (var prop in tab.PropertyTypes.OrderBy(x => x.SortOrder))
                        {
                            if (type.MemberCanEditProperty(prop.Alias))
                            {
                                int p = profileModel.MemberProperties.FindIndex(x => x.Alias == prop.Alias);
                                var propVal = profileModel.MemberProperties[p].Value;
                                var propName = profileModel.MemberProperties[p].Name;
    
                                            @Html.EditorFor(m => profileModel.MemberProperties[p].Value, ctrlType, new { CurrentProperty = profileModel.MemberProperties[p], CurrentPropertyType = prop, Extras = ExtrasObj })
                                            profileModel.MemberProperties[p].Name = ctrlType;
                                            @Html.HiddenFor(m => profileModel.MemberProperties[p].Name)
                                            @Html.HiddenFor(m => profileModel.MemberProperties[p].Alias)
    

    When the form is submitted you basically loop through the properties and save against the member.

    public ActionResult SaveProfile([Bind(Prefix = "profileModel")]ProfileModel profileModel)
    {
    for (int k = 0; k < profileModel.MemberProperties.Count; k++)
    

    Hope this helps, Regards L

Please Sign in or register to post replies

Write your reply to:

Draft