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

Inline editing : Create action is not fired

3 Answers 218 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Uday
Top achievements
Rank 1
Uday asked on 25 Jul 2014, 12:09 AM
Hi,

I am trying to implement a Grid with inline editing capability. Everything works fine except for the Create functionality. I am using a string for the Model Id.

.Model(model =>
{
    model.Id<string>(p => p.SalesRep.Id);
}

Here is what happens.. 
1) Click on Add New Record
2) Add a record in the client
3) Update any information
4) Clicking Update fires the Update action instead of create.

This is the example I am following: http://demos.telerik.com/aspnet-mvc/grid/editing-inline

I am not sure why the update action is being fired instead of create.

Could this be because of the Model Id is  a string. 

Below is a code snippet of the kendo grid. 
@(Html.Kendo().Grid<SalesRepViewModel>()
                                   .Name("SalesRepsGrid")
                                   .Columns(columns =>
                                   {
                                       columns.Bound(p => p.SalesRep).ClientTemplate("#=data.SalesRep.Name#");
                                       columns.Bound(p => p.SplitPercentage).Width(100);
                                       columns.Command(command => { command.Edit(); command.Destroy(); }).Width(172);
                                   })
                                   .ToolBar(toolbar => toolbar.Create())
                                   .Editable(editable => editable.Mode(GridEditMode.InLine))
                                   .DataSource(dataSource => dataSource
                                      .Ajax()
                                      .Events(events => events.Error("error_handler"))
                                      .Model(model =>
                                      {
                                          model.Id<string>(p => p.SalesRep.Id);
                                          model.Field(p => p.SalesRep.Id).Editable(false);
                                          model.Field(p => p.SplitPercentage).Editable(true);
                                          model.Field(p => p.SalesRep).DefaultValue(
                                                         ViewData["defaultSalesRep"] as NamedReferenceBindingModel<string>);
                                           
                                      })
                                      .Read(read => read.Action("SalesReps_Read", "PurchaseAgreement"))
                                      .Create(update => update.Action("SalesReps_Create", "PurchaseAgreement", new {                 purchaseAgreementId = Model.Id }))
                                      .Update(update => update.Action("SalesReps_Update", "PurchaseAgreement", new { purchaseAgreementId = Model.Id }))
                                      .Destroy(destroy => destroy.Action("SalesReps_Destroy", "PurchaseAgreement", new { purchaseAgreementId = Model.Id }))
                                     )
                              )

Most of the code above is same telerik grid inline editing example except for the model.

Any thoughts?



3 Answers, 1 is accepted

Sort by
0
Uday
Top achievements
Rank 1
answered on 25 Jul 2014, 12:29 AM
Looks like model Id cannot be a property with a property.

.Model(model =>{    model.Id<string>(p => p.SalesRep.Id);}

If I change my model to have an Id, it will work.

.Model(model =>{    model.Id<string>(p => p.Id);}



 
1
Accepted
Vladimir Iliev
Telerik team
answered on 28 Jul 2014, 03:21 PM
Hi Uday,

Basically the setting the model ID to nested property is not supported as the DataSource checks if current record is new by comparing the current value against the default value for current field. That why I would strongly suggest to flatter your model using ViewModel.

Regards,
Vladimir Iliev
Telerik
 

Check out the Telerik Platform - the only platform that combines a rich set of UI tools with powerful cloud services to develop web, hybrid and native mobile apps.

 
0
Uday
Top achievements
Rank 1
answered on 28 Jul 2014, 03:40 PM
Vladimir,

It makes total sense to me now. I ended up flattening my view model and it worked.

Thanks for your time.

Uday
Tags
Grid
Asked by
Uday
Top achievements
Rank 1
Answers by
Uday
Top achievements
Rank 1
Vladimir Iliev
Telerik team
Share this question
or