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!
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...
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!
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++)
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!
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
Hi L,
What are you trying to render?
What type is profileModel.MemberProperties[i].Value
What other properties do you have in ProfileModel?
Charlie :)
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!
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?
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:
The framework will look in ~/Views/Shared/EditorTemplates directory.
The razor code looks a little like this:
When the form is submitted you basically loop through the properties and save against the member.
Hope this helps, Regards L
is working on a reply...