【问题标题】:Get all roles in Nopcommerce 2.8获取 Nopcommerce 2.8 中的所有角色
【发布时间】:2013-08-31 23:42:08
【问题描述】:

我正在尝试获取在 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 个角色,但在我看来它们不像角色。我需要实际的角色名称。有谁知道我如何获得用户拥有的所有角色?谢谢。

【问题讨论】:

    标签: nopcommerce


    【解决方案1】:

    您需要在列表框中指定 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-01-14
      • 1970-01-01
      • 2023-03-21
      • 2016-08-04
      • 1970-01-01
      • 2022-10-24
      • 2021-10-06
      • 1970-01-01
      • 2014-05-08
      相关资源
      最近更新 更多