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!
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; }
}
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 }
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);
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!
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.
Thanks, Dan.
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
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:
Thanks, Dan.
Brilliant thanks Dan, although it seems like reinventing the wheel. Thanks for all your help. Best Regards, L
Found this with great examples
https://github.com/KrisJanssen/Umbraco7-Standard-Membership
Thanks Kris Janssen!
is working on a reply...