Post of values not appearing

5 posts, 0 answers
  1. Felipe Casanova
    Felipe Casanova avatar
    56 posts
    Member since:
    Feb 2010

    Posted 26 Mar 2012 Link to this post

    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
  2. Troy Clemons
    Troy Clemons avatar
    69 posts
    Member since:
    Apr 2010

    Posted 26 Mar 2012 Link to this post

    data: { bankId: $("#BankId").val(), confirmationRequestId: $("Request.Id").val() } 

    should be

    data: "{'bankId':'" + $("#BankId").val() + "','confirmationRequestId':'" + $("Request.Id").val() + "'}" 
  3. Kendo UI is VS 2017 Ready
  4. Felipe Casanova
    Felipe Casanova avatar
    56 posts
    Member since:
    Feb 2010

    Posted 26 Mar 2012 Link to this post

    Thanks but the grid populates ok so the read parameters are working. It is the update that isn't working.
  5. Troy Clemons
    Troy Clemons avatar
    69 posts
    Member since:
    Apr 2010

    Posted 26 Mar 2012 Link to this post

    sorry about that.

    let me know if you get a good answer as i am having the same issue on update currently.
  6. Rosen
    Admin
    Rosen avatar
    3234 posts

    Posted 27 Mar 2012 Link to this post

    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!
Back to Top
Kendo UI is VS 2017 Ready