1

我正在尝试获取在 NOPCOMMERCE 中分配给用户的所有角色。我知道如何确定用户是否具有特定角色,但我无法获取列表或列表框中的所有角色。

如果我使用以下代码:

Imports Nop.Core.Infrastructure
Imports Nop.Services.Helpers
Imports Nop.Core.Domain.Customers
Imports Nop.Services.Customers
Imports Nop.Core

ListBox1.DataSource = EngineContext.Current.Resolve(Of IWorkContext)().CurrentCustomer.CustomerRoles()
ListBox1.DataBind()

'this is the listbox on aspx page
<asp:ListBox ID="ListBox1" runat="server"></asp:ListBox>

我在列表框中得到了这个:

System.Data.Entity.DynamicProxies.CustomerRole_6E0DFC682B2D3247B3BEEED3063345A95D5742CE33B2761C4CB20A8C0A0AD639
System.Data.Entity.DynamicProxies.CustomerRole_6E0DFC682B2D3247B3BEEED3063345A95D5742CE33B2761C4CB20A8C0A0AD639
System.Data.Entity.DynamicProxies.CustomerRole_6E0DFC682B2D3247B3BEEED3063345A95D5742CE33B2761C4CB20A8C0A0AD639
System.Data.Entity.DynamicProxies.CustomerRole_6E0DFC682B2D3247B3BEEED3063345A95D5742CE33B2761C4CB20A8C0A0AD639

其中显示了 4 个角色,但它们在我看来不像角色。我需要实际的角色名称。有谁知道我如何获得用户拥有的所有角色?谢谢。

4

1 回答 1

0

您需要在列表框中指定 DataTextField 和 DataValueField 以告诉列表框 CustomerRole 的哪些字段将显示。

ListBox1.DataSource = EngineContext.Current.Resolve(Of IWorkContext)().CurrentCustomer.CustomerRoles()

//add this
ListBox1.DataTextField  = "SystemName"; //you can use "Name" instead of "SystemName" or whatever property name of CustomerRole class
ListBox1.DataValueField = "Id";

ListBox1.DataBind()
于 2013-09-04T09:53:34.410 回答