Am trying to retrieve a custom property (customproperty1) from a member however I am having trouble. Any thoughts. Example below (name works fine just not the custom one)
Thanks for the help Jeavon, have manged to retrieve the custom values using uQuery as you suggested. One question, is there an equivalent Member.GetCurrentMember in uQuery's uQuery.Get........ ? if not how do you get the current member logged on using uquery?
You just do the same as you had before using Member.GetCurrentMember() as the uQuery GetProperty is a extension method on the standard member object so should be available?
Right that makes sense. I did actually leave the GetCurrentMember in my code, just wanted to make sure that was correct. Thanks again for all your help.
Just for anyone interested, here's the final code as an example:
Is there any change, alternative new way of doing the below with update v7 member api? I cant seem to locate a clear reference where it indicates the equivalent of the below code in new alternate api v7. Would you know?
@using umbraco.cms.businesslogic.member
@{ var member = Member.GetCurrentMember(); <p>member.GetProperty<string>("customproperty1")) </p>
Get custom member properties with razor
Hi,
Am trying to retrieve a custom property (customproperty1) from a member however I am having trouble. Any thoughts. Example below (name works fine just not the custom one)
@using umbraco.cms.businesslogic.member
@using System.Web
@using System.Web.Security@{
var currentUser = Member.GetCurrentMember();
if (currentUser!=null){
var _userName = currentUser.Text;
var _customproperty1 = currentUser.getProperty("Customproperty1");
<p>@_userName </p>
<p>@_customproperty1 </p>
}
}
Hi Mark,
I think you are just missing a .Value
e.g.
var _customproperty1 = currentUser.getProperty("Customproperty1").Value
I generally perfer to use uQuery when working with members in Razor, there is an example in the docs here
Thanks,
Jeavon
Thanks for the help Jeavon, have manged to retrieve the custom values using uQuery as you suggested. One question, is there an equivalent Member.GetCurrentMember in uQuery's uQuery.Get........ ? if not how do you get the current member logged on using uquery?
Cheers,
Mark
Hi Mark,
You just do the same as you had before using Member.GetCurrentMember() as the uQuery GetProperty is a extension method on the standard member object so should be available?
Let me know if that works or not?
Cheers,
Jeavon
Hi Jeavon,
Right that makes sense. I did actually leave the GetCurrentMember in my code, just wanted to make sure that was correct. Thanks again for all your help.
Just for anyone interested, here's the final code as an example:
@using umbraco.cms.businesslogic.member
@{
var member = Member.GetCurrentMember();
if (member != null)
{
//member properties
<text>Name: </text>@member.Text<br/>
<text>Username: </text>@member.LoginName<br/>
<text>Email: </text>@member.Email<br/>
//custom properties
<text>Custom Property Text: </text>@(member.GetProperty<string>("customproperty1")) <br/>
}
}
Hi Mark, that's great!
There are a few other helpful methods for members available from uQuery such as HasProperty, full details here
Thanks,
Jeavon
Hi Jeavon
Is there any change, alternative new way of doing the below with update v7 member api? I cant seem to locate a clear reference where it indicates the equivalent of the below code in new alternate api v7. Would you know?
@using umbraco.cms.businesslogic.member
@{
var member = Member.GetCurrentMember(); <p>member.GetProperty<string>("customproperty1")) </p>
}
is working on a reply...