简体   繁体   中英

Get properties from Members in Umbraco (In Usercontrol)

I've made a Umbraco site, and ive got some members that i need to display information about in a usercontrol(ascx) page. But the only thing i can find is the old umbraco api, with the m.GetProperty(); method like:

foreach (Member m in Member.GetAll) {
    m.getProperty("danceStyles");
}

But visual studio says that Member is obsolete and i should use Membership instead, but i dont know how i can get generic properties from a member through that. Only thing i can get is Username , Email and Password , and not properties i define in umbraco...

Yah, Member.GetAll is obsolete but I suppose you could use Member.GetAllAsList() this method is to get members in List, This method works for me

foreach (var member in Member.GetAllAsList())
{
    // to get Property
    var property = member.getProperty("danceStyles");

    // to get Property Value
    var propertyValue = member.getProperty("danceStyles").Value;
}

Default properties of a member, such as Login, Email and Password can easily be referenced through .Net properties, however as you've noticed, custom properties can only be accessed by string.

The getProperty() method returns an umbraco.cms.businesslogic.property.Property object, so if you want to get/set the actual values of custom properties you've made, simply access the Value [.net] property of the [umbraco] property like so:

m.getProperty("danceStyles").Value

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM