I am using the generic UserProfile macro that I can use to allow Members to update their details via the website (not CMS) but I can only show Textboxes for each control. I have a DateTime Type, a True/False Type and I cant find a way to display these on the Profile page.
Im using the following code:
var profileModel = Members.GetCurrentMemberProfileModel();
@for (var i = 0; i < profileModel.MemberProperties.Count; i++) { @Html.LabelFor(m => profileModel.MemberProperties[i].Value, profileModel.MemberProperties[i].Name)
@*
By default this will render a textbox but if you want to change the editor template for this property you can
easily change it. For example, if you wanted to render a custom editor for this field called "MyEditor" you would
create a file at ~/Views/Shared/EditorTemplates/MyEditor.cshtml", then you will change the next line of code to
render your specific editor template like:
@Html.EditorFor(m => profileModel.MemberProperties[i].Value, "MyEditor")
*@
thanks for the reply. im not using custom dayatypes, im using umbraco datatypes such as the checkbox and datetime types and in my loop i need to detect these types so i can render the controls correctly. is this possible?
But 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.
So it would be better if you will create your own model and view for client side o f application.
Try to create a file at ~/Views/Shared/EditorTemplates/MyEditor.cshtml", then you will change the next line of code to render your specific editor template like:
@Html.EditorFor(m => profileModel.MemberProperties[i].Value, "MyEditor")
Razor has lots of different Html Helpers for rendering form controls, such as Html.CheckBoxFor() which will display your true/false checkbox.
For the date, there isn't a control that wil render a date-format out of the box, so you have to use something like JQuery-UI datepicker in conjunction with a textbox (Html.TextBoxFor())
I hope I've understood your problem correctly, and hope this helps?
I'm experimenting with custom editors, but I haven't actually got it working yet. I have a single custom property of type Textstring, and I'm trying to select it from a dropdown.
I've created a custom editor, which looks like this:
In my profile editor macro, my fieldset looks like this:
The only problem is that the property doesn't actually get saved... I tried changing the name, and that works, but my custom editor doesn't.
One thing I've noticed when looking at the generated html code is that the Name and Email fields have attributes for id, name, type, and value. Perhaps this is relevant.
I've sone some experimenting with these attributes, but with seemingly no effect. Perhaps I just haven't typed them correctly.
In any case, I'm out of ideas.
Jon, did you ever get this working? Or does anyone else here see what I might be doing wrong?
Regarding the custom editors, here is something that worked for me.
1) Render your form using the generic textboxes in your website, view the source and get the ID for the field that you want to render out with a custom editor. In my case the id was 5.
2) In your for loop, intercept that ID and render out the label, the hidden field and then specify your custom editor. Everything else that does not match your ID will get rendered with the default textbox:
3) In your custom editor, make sure you include the name and id attributes on the select with your correstponding id. I am sure there is a way to do this with Html helpers, but this will work:
The other option (preferred in my opinion) is just to render out the DDL in the if statement using an HTML helper. This way you can prepopulate the selected item as well like this:
if(i == 5)
{
@Html.LabelFor(m => profileModel.MemberProperties[i].Value, profileModel.MemberProperties[i].Name)
@Html.DropDownListFor(m => profileModel.MemberProperties[i].Value, new SelectList(
new List<Object>{
new { value = "" , text = "Please Select" },
new { value = "Ontario" , text = "Ontario" },
new { value = "Quebec" , text = "Quebec"},
new { value = "British Columbia" , text = "British Columbia"},
new { value = "Alberta" , text = "Alberta"},
new { value = "Manitoba" , text = "Manitoba"},
new { value = "Saskatchewan" , text = "Saskatchewan"},
new { value = "Nova Scotia" , text = "Nova Scotia"},
new { value = "New Brunswick" , text = "New Brunswick"},
new { value = "Newfoundland and Labrador" , text = "Newfoundland and Labrador"},
new { value = "Prince Edward Island" , text = "Prince Edward Island"},
new { value = "Northwest Territories" , text = "Northwest Territories"},
new { value = "Yukon" , text = "Yukon"},
new { value = "Nunavut" , text = "Nunavut"}
},"value","text",profileModel.MemberProperties[i].Value))
@Html.HiddenFor(m => profileModel.MemberProperties[i].Alias)
}
else
{
@Html.LabelFor(m => profileModel.MemberProperties[i].Value, profileModel.MemberProperties[i].Name)
@Html.EditorFor(m => profileModel.MemberProperties[i].Value)
@Html.HiddenFor(m => profileModel.MemberProperties[i].Alias)
}
Member Profile Page
Hi,
I am using the generic UserProfile macro that I can use to allow Members to update their details via the website (not CMS) but I can only show Textboxes for each control. I have a DateTime Type, a True/False Type and I cant find a way to display these on the Profile page.
Im using the following code:
var profileModel = Members.GetCurrentMemberProfileModel();
@for (var i = 0; i < profileModel.MemberProperties.Count; i++)
{
@Html.LabelFor(m => profileModel.MemberProperties[i].Value, profileModel.MemberProperties[i].Name)
@Html.EditorFor(m => profileModel.MemberProperties[i].Value)
@Html.HiddenFor(m => profileModel.MemberProperties[i].Alias)
<br />
}
But I cant find a way to find out what Datatype the control is.
Is this possible?
Jon
Hi Jon,
It's comment from that macro.
hi,
thanks for the reply. im not using custom dayatypes, im using umbraco datatypes such as the checkbox and datetime types and in my loop i need to detect these types so i can render the controls correctly. is this possible?
jon
Jon, yes this is possible.
But 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.
So it would be better if you will create your own model and view for client side o f application.
Thanks
Are there any examples on how to do this? I am quite new to MVC and not sure how you could create a partial view, inherit the Template etc.
Thanks
Any examples going?
Hi Jon,
Try to create a file at ~/Views/Shared/EditorTemplates/MyEditor.cshtml", then you will change the next line of code to render your specific editor template like: @Html.EditorFor(m => profileModel.MemberProperties[i].Value, "MyEditor")
Hi Jon,
Razor has lots of different Html Helpers for rendering form controls, such as Html.CheckBoxFor() which will display your true/false checkbox.
For the date, there isn't a control that wil render a date-format out of the box, so you have to use something like JQuery-UI datepicker in conjunction with a textbox (Html.TextBoxFor())
I hope I've understood your problem correctly, and hope this helps?
Cheers,
Maff
Jon, did you ever get this working?
I'm experimenting with custom editors, but I haven't actually got it working yet. I have a single custom property of type Textstring, and I'm trying to select it from a dropdown.
I've created a custom editor, which looks like this:
![]()
In my profile editor macro, my fieldset looks like this:
<fieldset>
<legend>Rediger profil</legend>
@Html.ValidationSummary("profileModel", true)
@Html.LabelFor(m => profileModel.Name)
@Html.TextBoxFor(m => profileModel.Name)
@Html.ValidationMessageFor(m => profileModel.Name)
<br />
@Html.LabelFor(m => profileModel.Email)
@Html.TextBoxFor(m => profileModel.Email)
@Html.ValidationMessageFor(m => profileModel.Email)
<br />
@* Custom editor *@
@Html.LabelFor(m => profileModel.MemberProperties[0].Value, profileModel.MemberProperties[0].Name)
@Html.EditorFor(m => profileModel.MemberProperties[0].Value, "LagEllerForeningEditor")
<br />
<button>Lagre</button>
</fieldset>
It renders ok:
![]()
The only problem is that the property doesn't actually get saved... I tried changing the name, and that works, but my custom editor doesn't.
One thing I've noticed when looking at the generated html code is that the Name and Email fields have attributes for id, name, type, and value. Perhaps this is relevant.
![]()
I've sone some experimenting with these attributes, but with seemingly no effect. Perhaps I just haven't typed them correctly.
![]()
In any case, I'm out of ideas.
Jon, did you ever get this working? Or does anyone else here see what I might be doing wrong?
Hi, I have the same problem... Did you found a solution for this !?
Found this with great examples
https://github.com/KrisJanssen/Umbraco7-Standard-Membership
Thanks Kris Janssen!
Regarding the custom editors, here is something that worked for me.
1) Render your form using the generic textboxes in your website, view the source and get the ID for the field that you want to render out with a custom editor. In my case the id was 5.
2) In your for loop, intercept that ID and render out the label, the hidden field and then specify your custom editor. Everything else that does not match your ID will get rendered with the default textbox:
3) In your custom editor, make sure you include the name and id attributes on the select with your correstponding id. I am sure there is a way to do this with Html helpers, but this will work:
The other option (preferred in my opinion) is just to render out the DDL in the if statement using an HTML helper. This way you can prepopulate the selected item as well like this:
is working on a reply...
This forum is in read-only mode while we transition to the new forum.
You can continue this topic on the new forum by tapping the "Continue discussion" link below.