0

バージョン 2.8 のビューで顧客の役割を取得するのを手伝ってくれる人はいますか? workcontext を試しましたが、「workcontext は現在のコンテキストに存在しません」というエラーが表示されます。以下のコードがありますが、動作しません..

@model BoardsIndexModel
@using Nop.Core.Infrastructure;
@using Nop.Services.Helpers;
@using Nop.Web.Models.Boards;
@using Nop.Core.Domain.Customers;
@using Nop.Services.Customers;


@if (Roles.IsUserInRole("Administrators"))
{
    Do that;
}
else
{
    Do this;
}
4

2 に答える 2

4

これは、nopcommerceフォーラムの素敵な人の助けを借りて、私がやった方法です:

@using Nop.Core.Domain.Customers;
@using Nop.Services.Customers;
@using Nop.Core;
@{
    bool customerHasRoleX = EngineContext.Current.Resolve<IWorkContext>().CurrentCustomer.IsInCustomerRole("Administrators");
    bool customerHasRoleY = EngineContext.Current.Resolve<IWorkContext>().CurrentCustomer.IsInCustomerRole("ForumModerators");
}

@if ((customerHasRoleX == true) | (customerHasRoleY == true)) {

}
else
{
    Response.Redirect("~/login?ReturnUrl=%2fboards");
}
于 2013-01-31T16:03:59.230 に答える
0

あなたが使用することができます、

@User.IsInRole("Administrators")
于 2013-01-30T18:34:20.190 に答える