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:21
    Luke
    0

    Rendering The Correct Property Editor

    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!

  • Dan Lister 416 posts 1974 karma points c-trib
    Sep 16, 2014 @ 16:17
    Dan Lister
    0

    Hi L,

    The property editors are only used for back office editing. The MemberProperties collection is just a list of strings (I think) so using the EditorFor() method will always show text inputs as you mentioned. If you wanted to use a MVC approach to editing member properties, you would be best off creating a View Model for the member. You'll be able to specify each property data type and have the helper method render the correct editor.

    public MemberViewModel
    {
        [DataType(DataType.MultilineText)]
        public string Comments { get; set; }
    
        [DataType(DataType.Password)]
        public string Password { get; set; }
    
        [DataType(DataType.EmailAddress)]
        public string EmailAddress { get; set; }
    }
    

    Thanks, Dan.

  • Luke 110 posts 256 karma points
    Sep 17, 2014 @ 10:20
    Luke
    0

    Hi Dan,

    Thank you for your reply! It is a good approach - but does not help getting the Umbraco data types (and prevalues) - or does it? For a simple example, I have created a drop down datatype for Name Title consisting of { Mr, Mrs, etc }

    Regards, L

  • Dan Lister 416 posts 1974 karma points c-trib
    Sep 17, 2014 @ 10:27
    Dan Lister
    0

    Hi L,

    If you wanted to get a collection of pre values for a given datatype, this documentation page might give you a little more information. You could use the following method to retrieve prevalues for a given data type:

    var dataTypeId = 1234;
    XPathNodeIterator iterator = umbraco.library.GetPreValues(dataTypeId);
    

    Thanks, Dan.

  • Luke 110 posts 256 karma points
    Sep 17, 2014 @ 10:31
    Luke
    0

    Brilliant thanks Dan, although it seems like reinventing the wheel. Thanks for all your help. Best Regards, L

  • Scott Devine 8 posts 73 karma points
    Jun 12, 2015 @ 03:29
    Scott Devine
    0

    Found this with great examples

    https://github.com/KrisJanssen/Umbraco7-Standard-Membership

    Thanks Kris Janssen!

Please Sign in or register to post replies

Write your reply to:

Draft