您可以按如下所示設置每列的可編輯屬性。
控制器:
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);
}
})
)
)