是否可以根据用户角色 hide/show Kendo 网格列?
Is it possible to hide/show Kendo grid column based on user role?
我在 asp.net MVC 中使用 Kendo ui 网格。是否可以 hide/show 基于用户角色的网格列?谢谢
最简单的方法是:
@(Html.Kendo().Grid(Model)
.Name("Grid")
.Columns(columns =>
{
columns.Bound(p => p.Id);
columns.Bound(p => p.Name);
if(User.IsInRole("Admin")) {
columns.Bound(p => p.AdminOnlyInfo);
}
})
...
)
您可以使用 hidden 指定列是否可见,因此一个选项可能是根据用户角色设置变量。例如,在控制器
ViewBag.CanDisplay = true; // or omit if the user does not have permission
并在视图中
var canDisplay = '@ViewBag.CanDisplay' | false;
$("#grid").kendoGrid({
columns: [
{ field: "firstProperty" },
{ field: "anotherProperty", hidden: !canDisplay }
],
我在 asp.net MVC 中使用 Kendo ui 网格。是否可以 hide/show 基于用户角色的网格列?谢谢
最简单的方法是:
@(Html.Kendo().Grid(Model)
.Name("Grid")
.Columns(columns =>
{
columns.Bound(p => p.Id);
columns.Bound(p => p.Name);
if(User.IsInRole("Admin")) {
columns.Bound(p => p.AdminOnlyInfo);
}
})
...
)
您可以使用 hidden 指定列是否可见,因此一个选项可能是根据用户角色设置变量。例如,在控制器
ViewBag.CanDisplay = true; // or omit if the user does not have permission
并在视图中
var canDisplay = '@ViewBag.CanDisplay' | false;
$("#grid").kendoGrid({
columns: [
{ field: "firstProperty" },
{ field: "anotherProperty", hidden: !canDisplay }
],