0
votes

I'm trying to set up batch edit on a grid in Kendo like the sample on their demo site- http://demos.kendoui.com/web/grid/editing.html . Everything seems set up correctly and it's posting the data correctly (it would seem) from the grid to the server. When I look at the post data in firebug it is all correct, but on the server when debugging the models sent back all contain null or empty string values. The number of models is showing correctly in the .Count, but they are empty. Here is my code and output, sorry I can't post images yet, not enough points on site yet:

aspx page:

<%: 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))
            )
        %>

controller:

[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 the 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

Debug model (_modelSummary in controller) on server, all data is empty or 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

Thanks for any help on this.

1
See this post for issue resolved. stackoverflow.com/questions/17495762/… That did it for me. I hope it helps you too. - user906573

1 Answers

1
votes

I modified your DataSource Model. Your primary ID must be 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);
                })