我正尝试在Kendo中的网格上设置批量编辑,就像他们的演示网站http://demos.kendoui.com/web/grid/editing.html上的示例一样。一切似乎都是正确设置的,而且它也正确地将数据从网格发送到服务器(看起来似乎如此)。当我查看firebug中的post数据时,它是正确的,但在服务器上调试时,发回的模型都包含null或空字符串值。模型的数量在.Count中正确显示,但它们是空的。这是我的代码和输出,很抱歉我还不能发布图片,网站上还没有足够的点数:
aspx页面:
<%: 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),所有数据为空或为空:
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谢谢你在这方面的帮助。
发布于 2013-08-02 06:32:46
我修改了你的DataSource模型。您的主ID必须为默认值。
.Model(model =>
{
model.Id(j => j.ModelID);
model.Field(p => p.ModelID).DefaultValue(16000000);
model.Field(j => j.ModelID).Editable(false);
model.Field(j => j.ModelNumber).Editable(false);
})https://stackoverflow.com/questions/16161426
复制相似问题