【问题标题】:How do you disable editting on a Kendo Grid in MVC using code behind?如何使用隐藏代码在 MVC 中禁用 Kendo Grid 上的编辑?
【发布时间】:2014-01-13 21:49:13
【问题描述】:
在我的控制器中,我想检查表单的截止日期是否已过,然后将 Kendo 网格设置为仅可查看且不可编辑。否则我希望它是可编辑的。
我可以在后面的代码中设置 Viewbag 属性,然后在客户端进行更改,但我希望在所有服务器端都这样做。这可能吗?我对 MVC 有点陌生,我对使用 ASP.NET 网格如此简单感到沮丧。
在 MVC 中禁用网格的方法背后的代码是什么?
我也是 Kendo 的新手,所以我不太确定如何在 Kendo UI 网格客户端禁用编辑。所以任何可能的方式我都可以!
【问题讨论】:
标签:
jquery
asp.net-mvc
kendo-ui
kendo-grid
kendo-asp.net-mvc
【解决方案1】:
您可以如下设置每列的可编辑属性。
控制器:
public ActionResult Index()
{
ProductModel model = new ProductModel();
model.lst_product = rep.ReadAll();
model.myvar = "no_edit";
return View(model);
}
查看:
@model MtBarkerApplication.Models.ProductModel
@(Html.Kendo().Grid((IEnumerable<MtBarkerApplication.Models.ProductModel>)Model.lst_product)
.Name("grid")
.Columns(columns =>
{
columns.Bound(o => o.ProductID).Visible(false);
columns.Bound(o => o.ProductCode).Title("Product Code");
columns.Bound(o => o.ProductDescription).Title("Product Description");
columns.Command(command => { command.Edit(); command.Destroy(); }).Width(182);
})
.ToolBar(toolbar => toolbar.Create())
.Editable(editable => editable.Mode(GridEditMode.InLine))
.Pageable()
.Sortable()
.Filterable()
.DataSource(dataSource => dataSource
.Ajax()
.PageSize(50)
.Events(events => events.Error("error_handler"))
.Model(model => model.Id(p => p.ProductID))
.Create(update => update.Action("EditingInline_Create", "Product"))
.Read(read => read.Action("EditingInline_Read", "Product"))
.Update(update => update.Action("EditingInline_Update", "Product"))
.Destroy(update => update.Action("EditingInline_Destroy", "Product"))
.Model(model =>
{
if (Model.myvar == "no_edit")
{
model.Field(p => p.ProductCode).Editable(false);
}
})
)
)