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

Post of values not appearing

4 Answers 54 Views
Data Source
This is a migrated thread and some comments may be shown as answers.
Felipe Casanova
Top achievements
Rank 1
Felipe Casanova asked on 26 Mar 2012, 09:15 PM
Can anyone see what is wrong with this please? I populate a grid. When I edit a row in the grid and choose save changes I have a controller action method being called by the datasource but I get a collection with one empty object - all properties are null or 0. 

var datasource = new kendo.data.DataSource({
         transport: {
            read: {
                url: "/AccountDetails/IndexForRequest/" + $("#Request.Id").val(),
                dataType: "json",
                data: { bankId: $("#BankId").val(), confirmationRequestId: $("Request.Id").val() }
            },
            update: {
                url: "/AccountDetails/EditForRequest",
                 
                type: 'POST',
                dataType: "json"
            },
            destroy: {
                url: "/AccountDetails/DeleteForRequest",
                type: 'POST',
                dataType: "json"
            },
            create: {
                url: "/AccountDetails/CreateForRequest",
                type: 'POST',
                dataType: "json"
            }
        },
        batch: true,
        pageSize: 30,
        schema: {
            model: {
                id: "Id",
                fields: {
                    Id: { editable: false, nullable: true },
                    Client: { editable: false, nullable: true },
                    Balance: { editable: false, nullable: true, type: "number" },
                    Currency: { editable: false, nullable: true },
                    EntityName: { editable: true, nullable: false, validation: { required: true } },
                    AccountName: { editable: true, nullable: true },
                    AccountNumber: { editable: true, nullable: false, validation: { required: true } },
                    SortCode: { editable: true, nullable: false, validation: { required: true } }
                }
            }
        }
    });


My controller action is...

[HttpPost]
public JsonResult EditForRequest(IList<
AccountDetailDto> models)
        {
            List<AccountDetailDto> returnObject = GenerateAccountDataForClientA();
            return new JsonResult()
            {
                Data = returnObject,
                JsonRequestBehavior = JsonRequestBehavior.AllowGet
            };
        }

Thanks

4 Answers, 1 is accepted

Sort by
0
Troy Clemons
Top achievements
Rank 1
answered on 26 Mar 2012, 09:29 PM
data: { bankId: $("#BankId").val(), confirmationRequestId: $("Request.Id").val() } 

should be

data: "{'bankId':'" + $("#BankId").val() + "','confirmationRequestId':'" + $("Request.Id").val() + "'}" 
0
Felipe Casanova
Top achievements
Rank 1
answered on 26 Mar 2012, 09:36 PM
Thanks but the grid populates ok so the read parameters are working. It is the update that isn't working.
0
Troy Clemons
Top achievements
Rank 1
answered on 26 Mar 2012, 10:49 PM
sorry about that.

let me know if you get a good answer as i am having the same issue on update currently.
0
Rosen
Telerik team
answered on 27 Mar 2012, 09:44 AM
Hi Matt,

I guess that most probably the issue you have described is caused by incorrect format of the data send to the server. ASP.NET MVC ModelBinder will require request parameters to be in specific format in order the action parameters to be bound. Please refer to this demo project which demonstrates CRUD operations using Grid widget and ASP.NET MVC.
 
All the best,
Rosen
the Telerik team
Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
Tags
Data Source
Asked by
Felipe Casanova
Top achievements
Rank 1
Answers by
Troy Clemons
Top achievements
Rank 1
Felipe Casanova
Top achievements
Rank 1
Rosen
Telerik team
Share this question
or