简体   繁体   English

从Umbraco中的成员获取属性(在Usercontrol中)

[英]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. 我已经建立了一个Umbraco网站,并且ive拥有一些我需要在usercontrol(ascx)页面上显示有关信息的成员。 But the only thing i can find is the old umbraco api, with the m.GetProperty(); 但是我唯一能找到的是带有m.GetProperty();的旧umbraco api 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. 但是Visual Studio表示Member已过时,我应该改用Membership ,但是我不知道如何通过该方式从会员那里获得通用属性。 Only thing i can get is Username , Email and Password , and not properties i define in umbraco... 我唯一能得到的是UsernameEmailPassword ,而不是我在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 是的, Member.GetAll已过时,但是我想您可以使用Member.GetAllAsList()这个方法来获取List中的成员,该方法对我Member.GetAllAsList()

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. 成员的默认属性,例如Login,Email和Password,可以通过.Net属性轻松引用,但是,您已经注意到,只能通过字符串访问自定义属性。

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: getProperty()方法返回一个umbraco.cms.businesslogic.property.Property对象,因此,如果要获取/设置已创建的自定义属性的实际值,只需访问[umbraco]的Value [.net]属性]属性,如下所示:

m.getProperty("danceStyles").Value

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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