剑道UI网格批量保存-模型在服务器上发布后清空



我正试图在剑道的网格上设置批量编辑,就像他们的演示网站- 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);
}

Post Data Going to Server:

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

谢谢你的帮助。

我修改了你的数据源模型。主ID必须为defaultvalue。

.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);
                })

最新更新