This is a migrated thread and some comments may be shown as answers.

Null Model being passed with inline edit

1 Answer 611 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Jason
Top achievements
Rank 1
Jason asked on 05 May 2015, 09:02 PM

Seeing an odd issue trying to setup some inline editing using the Grid controller.  The Grid displays correctly and functions correctly until I try to perform an edit.  When I click the edit button, make edits and then press update, the line comes back with empty values.

 Upon inspection, the model being passed to the controller ActionResult is null (expect for ID and date).  Code below.  Took a look at some of the null threads and not seeing a common denominator.  Any thoughts:

Grid Control:

 

@(Html.Kendo().Grid(Model)
        .Name("commissionGrid")
        .Columns(columns =>
        {
            columns.Bound(p => p.CommissionId);
            columns.Bound(p => p.TenantId);
            columns.Bound(p => p.SimpleName);
            columns.Bound(p => p.StartDate);
            columns.Bound(p => p.CustomerName);
            columns.Bound(p => p.CustomerNumber);
            columns.Command(command =>
            {
                command.Edit();
            }).Title("Commands");
        })
        .Editable(editable => editable.Mode(GridEditMode.InLine))
        .Pageable()
        .Navigatable()
        .Sortable()
        .DataSource(dataSource => dataSource
            .Ajax()
            .Batch(true)
            .PageSize(10)
            //.ServerOperation(false)
            .Model(model => model.Id(p => p.CommissionId))
            .Update(update => update.Action("EditingInline_Update", "Commissions"))
 
        )
        )

Controller:

[AcceptVerbs(HttpVerbs.Post)]
        public ActionResult EditingInline_Update([DataSourceRequest] DataSourceRequest request, CommissionViewModel commissionViewModel)
        {
             
              
            if (commissionViewModel != null && ModelState.IsValid)
            {
 
 
                using (var test = new CommissionContext())
                {
                    try
                    {
                        var entity = new Commission();
 
                        entity.CommissionId = commissionViewModel.CommissionId;
                        entity.CustomerName = commissionViewModel.CustomerName;
                        entity.CustomerNumber = commissionViewModel.CustomerNumber;
                        entity.SimpleName = commissionViewModel.SimpleName;
                        entity.StartDate = commissionViewModel.StartDate;
                        entity.TenantId = commissionViewModel.TenantId;
 
                        test.Commissions.Attach(entity);
                        test.Entry(entity).State = EntityState.Modified;
                        test.SaveChanges();
                    }
 
                    catch (System.Data.Entity.Validation.DbEntityValidationException v)
                    {
                        Console.WriteLine("Exception is {0}", v);
                    }
                }
            }
            return Json(new[]{commissionViewModel}.ToDataSourceResult(request, ModelState));
        }

 

1 Answer, 1 is accepted

Sort by
0
Jason
Top achievements
Rank 1
answered on 05 May 2015, 09:30 PM

Figures... Finally felt like I had to post and then fixed it with a bit more elbow grease.

 

Had the .batch(true) set from a previous implementation.  Le sigh....

Tags
Grid
Asked by
Jason
Top achievements
Rank 1
Answers by
Jason
Top achievements
Rank 1
Share this question
or