我正在尝试在 Kendo 的网格上设置批量编辑,就像他们的演示站点上的示例一样 - http: //demos.kendoui.com/web/grid/editing.html 。一切似乎都设置正确,并且将数据正确(看起来)从网格发布到服务器。当我在 firebug 中查看 post 数据时,一切都是正确的,但是在服务器上调试时,发回的模型都包含 null 或空字符串值。.Count 中正确显示了模型的数量,但它们是空的。这是我的代码和输出,抱歉我还不能发布图片,现场还没有足够的积分:
页面:
<%: Html.Kendo().Grid<Thread.Site.Models.ModelSummary>()
.Name("Grid")
.Columns(columns =>
{
columns.Bound(m => m.ModelID).Hidden();
columns.Bound(m => m.ModelNumber).Width(100).ClientTemplate("#= (ModelNumber === 'null') ? ' ' : ModelNumber #");
columns.Bound(m => m.ModelName);
columns.Bound(m => m.Content).Width(160);
columns.Bound(m => m.Bullet1);
columns.Bound(m => m.Bullet2);
columns.Bound(m => m.Bullet3);
columns.Bound(m => m.Bullet4);
columns.Bound(m => m.Bullet5);
columns.Bound(m => m.Bullet6);
columns.Bound(m => m.AlertCount).ClientTemplate("# if (AlertCount > 0) { # <span class='icons icons-alert viewCheck' title='#= AlertCount # Alert(s)'></span> #}#").Title("Attention");//"#= (AlertCount === 0) ? ' ' : AlertCount #").Title("Attention");//
})
.Pageable()
.ToolBar(
toolbar => {toolbar.Save();}
)
.Editable(edit => { edit.Mode(Kendo.Mvc.UI.GridEditMode.InCell); })
.Navigatable(n => { n.Enabled(true);})
.Sortable()
.Scrollable(s=>s.Height(500))
.Selectable(selectable => selectable.Mode(Kendo.Mvc.UI.GridSelectionMode.Single))
.Filterable()
.Events(events =>
{
events.DataBound("dataBound");
events.Edit("edit");
events.Change("change");
})
.DataSource(dataSource => dataSource
.Ajax()
.Batch(true)
.ServerOperation(false)
.PageSize(15)
.Events(events => events.Error("error_handler"))
.Model(model =>
{
model.Id(j => j.ModelID);
model.Field(j => j.ModelID).Editable(false);
model.Field(j => j.ModelNumber).Editable(false);
})
.Read(read => read.Action("ModelList_Read", "Models", new { jobID = job.JobID }))
.Update(update => update.Action("ModelList_SaveAll", "Models").Type(HttpVerbs.Post))
)
%>
控制器:
[Authorize]
[AcceptVerbs(HttpVerbs.Post)]
public ActionResult ModelList_SaveAll([DataSourceRequest] DataSourceRequest request, [Bind(Prefix = "models")] IEnumerable<Thread.Site.Models.ModelSummary> modelSummary)
{
if (modelSummary != null)
{
foreach (Thread.Site.Models.ModelSummary _modelSummary in modelSummary)
{
ModelRepository.SetModelCopies(CurrentUser.ProfileID, modelCopiesSend);
}
}
return Json(new[] { modelSummary }.ToDataSourceResult(request, ModelState), JsonRequestBehavior.AllowGet);
}
将数据发布到服务器:
models[0][ActiveFlag] false
models[0][AlertCount] 0
models[0][Bullet1ID] 0
models[0][Bullet1] test bullet 1
models[0][Bullet2ID] 0
models[0][Bullet2] test bullet 2
models[0][Bullet3ID] 0
models[0][Bullet3]
models[0][Bullet4ID] 0
models[0][Bullet4]
models[0][Bullet5ID] 0
models[0][Bullet5]
models[0][Bullet6ID] 0
models[0][Bullet6]
models[0][CompanyID] 16
models[0][Complete] false
models[0][ContentID] 0
models[0][Content] test description here
在服务器上调试模型(控制器中的_modelSummary),所有数据为空或null:
modelSummary.Count = 1
Bullet1 null string
Bullet1ID 0 int
Bullet2 null string
Bullet2ID 0 int
Bullet3 null string
Bullet3ID 0 int
Bullet4 null string
Bullet4ID 0 int
Bullet5 null string
Bullet5ID 0 int
Bullet6 null string
Bullet6ID 0 int
CompanyID 0 int
感谢您对此的任何帮助。