我刚刚开始学习Kendo UI MVC并且遇到了以下问题。这是我的代码:
@(Html.Kendo().Grid<JeffreysOnline.Entities.Customer>()
.Name("grid")
.Columns(columns =>
{
columns.Bound(p => p.FirstName);
columns.Bound(p => p.LastName);
columns.Bound(p => p.Address);
columns.Command(command => { command.Edit(); command.Destroy(); }).Width(250);
})
.ToolBar(toolbar => toolbar.Create())
.Editable(editable => editable.Mode(GridEditMode.InLine))
.Pageable()
.Sortable()
.Scrollable()
.HtmlAttributes(new { style = "height:550px;" })
.DataSource(dataSource => dataSource
.Ajax()
.PageSize(20)
.Events(events => events.Error("error_handler"))
.Model(model => model.Id(p => p.ProductID))
.Create(update => update.Action("EditingInline_Create", "Grid"))
.Read(read => read.Action("EditingInline_Read", "Grid"))
.Update(update => update.Action("EditingInline_Update", "Grid"))
.Destroy(update => update.Action("EditingInline_Destroy", "Grid"))
)
)
我收到以下错误,第23行突出显示。
Compiler Error Message: CS1660: Cannot convert lambda expression to type 'string' because it is not a delegate type
Line 21: .Scrollable()
Line 22: .HtmlAttributes(new { style = "height:550px;" })
Line 23: .DataSource(dataSource => dataSource
Line 24: .Ajax()
Line 25: .PageSize(20)
它似乎不喜欢数据源&#39;但我不知道它会期待什么。
答案 0 :(得分:1)
如果ProductId不是您模型的属性,则可能导致错误。
您似乎直接从telerik的内联编辑教程页面中获取了示例:http://demos.telerik.com/aspnet-mvc/grid/editing-inline,因此请尝试在数据源中调整指向模型的列。像这样:
.DataSource(dataSource => dataSource
.Ajax()
.PageSize(20)
.Events(events => events.Error("error_handler"))
.Model(model => model.Id(p => p.RandyMindersActualIdColumnProperty)) // Here is the change
.Create(update => update.Action("EditingInline_Create", "Grid"))
.Read(read => read.Action("EditingInline_Read", "Grid"))
.Update(update => update.Action("EditingInline_Update", "Grid"))
.Destroy(update => update.Action("EditingInline_Destroy", "Grid"))
)