If you have the Id/Guid that represents the Member you can get the Member object as IPublishedContent by writing
var pickedMemberId = "yourguididfromthepicker";
var pickedMember = Umbraco.TypedMember(pickedMemberId);
if (pickedMember!=null){
var memberName = pickedMember.Name;
var someProperty = pickedMember.GetPropertyValue<string>("someProperty");
}
Unfortunately this didn't work for me, The solution that did i've marked below :)
Many thanks again!
Sam
The code:
//This is the Business Guid
var businessGuid = member.GetValue<string>("business");
//Marc Forum solution
var pickedMemberId = businessGuid;
var pickedMember = Umbraco.TypedMember(pickedMemberId);
if (pickedMember != null)
{
var memberName = pickedMember.Name;
var someProperty = pickedMember.GetPropertyValue<string>("business");
<p>@memberName</p>
<p>@someProperty</p>
}
It seems you are using on of the latest Umbraco versions (since the green toogle button (checkbox) has been modified recently).
If you have PropertyValueConverters enabled, which it should be by default in new projects, I think you can get the
@{
var currentMember = Members.GetCurrentMember();
var business = currentMember.GetPropertyValue<IEnumerable<IPublishedContent>>("business");
if (business != null)
{
var name = business.FirstOrDefault().Name;
}
}
I am not sure which property editor (datatype) you are using for the property "business" - if it is Multi Node Tree Picker (MNTP) you need to cast it to IEnumerable<IPublishedContent>> for other property editors just IPublishedContent.
As you suggested i just needed to use the IPublishedContent.
Below is the code that worked:
@{
var currentMember = Members.GetCurrentMember();
var business = currentMember.GetPropertyValue<IPublishedContent>("business");
if (business != null)
{
var name = business.Name;
<p>@name</p>
}
--Side note--
If i wanted to get the same values in a controller to pass to a model, how would i do this?
Currently i am
Getting the memberId.
Then getting the Guid.
Stripping off 'umb://member/' from the Guid
Writing a SQL query to get the name of the business from the text column in umbracoNode table WHERE Guid = Guid.
If you are using a Member Picker (Umbraco.MemberPicker2), you should be able to get it the selected member by using either .GetPropertyValue<IPublishedContent>("business") or .GetPropertyValue<IEnumerable<IPublishedContent>>("business"), but first you need to get the member (or content node) with this property.
If you are using ModelsBuilder Dll mode, you can use something like this if you deal with a specific member type:
var member = Members.GetCurrentMember();
var customer = member.OfType<Umbraco.Web.PublishedContentModels.Customer>();
if (customer != null)
{
var business = customer.Business;
}
Custom member property
Hi,
I am trying to get a property from the members area of the backend and cannot get it out easily!
I have added a member picker to the members tab to assign a 'business'
When in the view i ask for the name of the assigned business i only get an ID or a guid.
How do i get the text name/value of this property?
Images and code below.
Any help much appreciated or suggestions :)
Many thanks, Sam
Member picker
Hi Sam
If you have the Id/Guid that represents the Member you can get the Member object as IPublishedContent by writing
if I've understood correctly!
regards
Marc
Hi Marc,
Thank you for your reply.
Unfortunately this didn't work for me, The solution that did i've marked below :)
Many thanks again!
Sam
The code:
Hi Sam
It seems you are using on of the latest Umbraco versions (since the green toogle button (checkbox) has been modified recently).
If you have PropertyValueConverters enabled, which it should be by default in new projects, I think you can get the
I am not sure which property editor (datatype) you are using for the property "business" - if it is Multi Node Tree Picker (MNTP) you need to cast it to
IEnumerable<IPublishedContent>>
for other property editors justIPublishedContent
./Bjarne
Hi Bjarne,
The below code worked for me!
As you suggested i just needed to use the IPublishedContent.
Below is the code that worked:
--Side note-- If i wanted to get the same values in a controller to pass to a model, how would i do this?
Currently i am
Is there an easier way?
Many thanks,
Sam.
Hi Sam
I you have either a custom controller as a
RenderMvcController
for your page https://our.umbraco.com/documentation/reference/routing/custom-controllers or aSurfaceController
which is a part of the page https://our.umbraco.com/documentation/reference/routing/surface-controllers for part of your page e.g. with a form or another component, then you should be able to either get the property on the current member or getting a specific member and map these values to your custom model.If you are using a Member Picker (
Umbraco.MemberPicker2
), you should be able to get it the selected member by using either.GetPropertyValue<IPublishedContent>("business")
or.GetPropertyValue<IEnumerable<IPublishedContent>>("business")
, but first you need to get the member (or content node) with this property.If you are using ModelsBuilder Dll mode, you can use something like this if you deal with a specific member type:
/Bjarne
Hi Bjarne,
I will give this a try and let you know how i get on :)
Many thanks, Sam
Hi Bjarne,
This solution worked perfectly!
Thank you
Sam
is working on a reply...