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

[Solved] Batch Editing Binding Issue

2 Answers 156 Views
Grid
This is a migrated thread and some comments may be shown as answers.
This question is locked. New answers and comments are not allowed.
Guilherme
Top achievements
Rank 1
Guilherme asked on 01 Aug 2012, 08:04 PM
Hello Telerik People

I have created a simple application which entities as Order and OrderRow.
Wtih a Grid in InCell editing mode I'm managing some data.

@{Html.Telerik().Grid<Volvo.POS.MVCWebUIComponent.Models.Entities.OrderRow>()
 
    .Name("GridOrderRowRequest")
    .DataBinding(bind => bind.Ajax()
        .Select("GridOrderRowRequest_Select", "Order")
        .Update("GridOrderRowRequest_Update", "Order", new { orderNumber = Model.Number }))
    .DataKeys(conf => conf.Add(exp => exp.Number))
    .Columns(columns =>
    {
        columns.Bound(o => o.Number).Visible(true);
        columns.Bound(o => o.Part.Name).Width(180).Title("Name").ReadOnly();
        columns.Bound(o => o.RequestedQuantity).Title("Request").Format("{0:d} (click to edit)");
    })
    .ClientEvents(e => {
        e.OnDataBinding("GridOrderRowRequest_OnDataBinding");
        e.OnEdit("GridOrderRowRequest_OnEdit");
        e.OnSave("GridOrderRowRequest_OnSubmitChanges");
    })
    .Editable(e => e.Mode(GridEditMode.InCell))
    .Selectable()
    .Scrollable(conf => conf.Height(150))
    .Render();
}


But I have handling the buttons events on my own. So I have something like:

grid.insertRow(data.Content);
grid.submitChanges();

I receive the data in a controller method, something like:

[GridAction]
        [HttpPost]
        public ViewResult GridOrderRowRequest_Update(
            [Bind(Prefix = "inserted")]IEnumerable<Entities.OrderRow> insertedOrderRows,
            [Bind(Prefix = "updated")]IEnumerable<Entities.OrderRow> updatedOrderRows,
            [Bind(Prefix = "deleted")]IEnumerable<Entities.OrderRow> deletedOrderRows,
            int orderNumber)
        {
...

For some reason in the updatedOrderRows, when I'm editing some existent data, the Number field from my entity is not binded with the values sent. But this happend only with Number, all others fields are ok.

To solve this I had to use some ugly code like:
orderRow.Number = Convert.ToInt32(HttpContext.Request.Form["updated[" + i + "].Number"]);

Since I dont need the Number, the insert function are ok.

Do you know why? ??

Regards

Guilherme

2 Answers, 1 is accepted

Sort by
0
Petur Subev
Telerik team
answered on 06 Aug 2012, 07:58 AM
Hi Guilherme,

I believe the reason for this behavior is that the ModelBinder is getting the value from the route values not from the form data because you have datakey called Number (which contains the original value):
.DataKeys(conf => conf.Add(exp => exp.Number))
and also you have a column with the same name (which should contain the updated value).
columns.Bound(o => o.Number).Visible(true); 

Could you try to use different name for the RouteKey and see if it helps?
e.g.
.DataKeys(keys=>keys.Add(p=>p.Number).RouteKey("NumberKey"))


Kind Regards,
Petur Subev
the Telerik team
Check out the successor of Telerik MVC Extensions - Kendo UI for ASP.NET MVC - and deem it for new ASP.NET MVC development.
0
Guilherme
Top achievements
Rank 1
answered on 06 Aug 2012, 03:46 PM
Finally I discovered the reason.

In the OrderRow entity, I had:
[ReadOnly(true)]
public int Number { get; set; }

The attribute ReadOnly just tell to ModelBinder to dont bind.
After I removed it, everything start to work again :)

Thanks anyway!
Tags
Grid
Asked by
Guilherme
Top achievements
Rank 1
Answers by
Petur Subev
Telerik team
Guilherme
Top achievements
Rank 1
Share this question
or