根据Viewbag条件使Kendo ASP.NET MVC inCell可编辑

发布于 2025-01-17 00:21:28 字数 354 浏览 2 评论 0原文

是否可以基于仅当您有某个 Viewbag 时才允许编辑的函数来制作 Kendo MVC 网格 .Editable() ?

我有一个名为 Viewbag.DisplayButton 的视图包。仅当您具有开发人员角色时,该 viewbag 才是“true”(因此非开发人员无法编辑任何内容)。我怎样才能使这个工作与 .Editable() 一起工作,以便您只能在有该 viewbag 的情况下编辑单元格?

目前,如果我设置 Editable(true),那么任何人(开发人员、客户,实际上任何人)都可以编辑单元格。如果我将其设置为可编辑(假),那么包括开发人员在内的任何人都无法编辑它。因此,我需要一个仅在您拥有特定视图包时才执行此操作的函数。

Is it possible to make a Kendo MVC grid .Editable() based on a function that allows editing ONLY if you have a certain Viewbag?

I have a viewbag that is Viewbag.DisplayButton. That viewbag is only 'true' if you have a dev role (so non-devs cannot edit anything). How can I make this work with .Editable() so that you can only edit cells if you have that viewbag?

Currently if I set Editable(true) then anyone (devs, customers, literally anyone) can edit the cell. If I set it to Editable(false) then no one, including devs, can edit it. So I need a function that does it only if you have that specific viewbag.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

一身骄傲 2025-01-24 00:21:28

为此,请使用 Razor 代码块。您可以将网格定义分配给变量,然后执行条件逻辑并添加其他配置(如果有)。最后调用Render方法。这是一个例子:

<h3>Some content</h3>
@{
  var isAdmin = true;

  var grid = (Html.Kendo().Grid<MyModel>()
             .Name("grid")
             .Columns(columns =>
             {
                 columns.Bound(p => p.MyModelID).Filterable(false);
                 columns.Bound(p => p.SomeModelProperty);
             })
             .Pageable()
             .Scrollable()
             .DataSource(dataSource => dataSource
                 .Ajax()
                 .PageSize(20)
                 .Model(m=>m.Id("MyModelID"))
                 .Read(read => read.Action("Read", "Grid"))
             )
         );

  if (User.IsInRole("Admin"))
  {
      grid.Editable(e=>e.Mode(GridEditMode.InCell));
  }

  grid.Render();
}
<h3>Some other content</h3>

Use a Razor code block for this. You can assign the Grid definition to a variable, then execute the conditional logic and add the additional configurations, if any. Finally call the Render method. Here is an example:

<h3>Some content</h3>
@{
  var isAdmin = true;

  var grid = (Html.Kendo().Grid<MyModel>()
             .Name("grid")
             .Columns(columns =>
             {
                 columns.Bound(p => p.MyModelID).Filterable(false);
                 columns.Bound(p => p.SomeModelProperty);
             })
             .Pageable()
             .Scrollable()
             .DataSource(dataSource => dataSource
                 .Ajax()
                 .PageSize(20)
                 .Model(m=>m.Id("MyModelID"))
                 .Read(read => read.Action("Read", "Grid"))
             )
         );

  if (User.IsInRole("Admin"))
  {
      grid.Editable(e=>e.Mode(GridEditMode.InCell));
  }

  grid.Render();
}
<h3>Some other content</h3>
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文