ListView update issues

5 posts, 0 answers
  1. Justin
    Justin avatar
    3 posts
    Member since:
    Apr 2013

    Posted 24 Sep 2013 Link to this post

    Hello,

         Let me preface this question with the fact that we are very new to List Views and Kendo UI in general. We are developing our project with MVC and using the client side (non-server side wrapper) approach to the Kendo UI List Views. We pass JSON down to the view and render the List View with no problems. We can add list items fine as well. The only issue is when we try to update/delete a record we are not properly returning JSON back to our controller server side.  I believe the issue is in our ParameterMap code:

    I have tested to ensure that the JSON data in parameter map is valid for the record updated and picks up the change. 
            $(document).ready(function () {
                dataSource = new kendo.data.DataSource({
                    transport: {
                        read: {
                            url: 'Read',
                            dataType: 'json'
                        },
                        destroy: {
                            url: 'Destroy',
                            dataType: 'json'
                        },
                        create: {
                            url: 'Create',
                            dataType: 'json'
                        },
                        update: {
                            url: 'Update',
                            dataType: 'json'
                        },
                        parameterMap: function (data, operation) {
                            if (operation == "update") {
                                return kendo.stringify(data); //what to return here?
                            } 
                        }

                    },
                    schema: {
                        data: 'Data',
                        model: {
                            id: 'LoanNumber',
                            fields: {
                                LoanNumber: 'LoanNumber',
                                PrimaryCifNumber: 'PrimaryCifNumber',
                                GrossLoanAmount: 'GrossLoanAmount',
                                Opit: 'Opit',
                                RefinanceAmount: 'RefinanceAmount',
                                LoanLeaseType: 'LoanLeaseType',
                                RepaymentType: 'RepaymentType',
                                LoanLeaseTermMonths: 'LoanLeaseTermMonths',
                                RepaymentFrequency: 'RepaymentFrequency',
                                PreApproval: 'PreApproval',
                                CollateralType: 'CollateralType'
                            }
                        }
                    }
                });
                var listView = $("#LineofCreditsListView").kendoListView({
                    selectable: true,
                    navigatable: true,
                    editable: true,
                    dataSource: dataSource,
                    template: kendo.template($("#template").html()),
                    editTemplate: kendo.template($("#editTemplate").html()),
                }).data("kendoListView");

    Our controller/Action Method for update  is actually reached when committing the update but nothing is in the parameter request

    public void Update(JsonResult request)
            {
                //update DB
            }
    My question is - what is the standard way of passing in JSON to an action method for update? We want to stay away from the server side wrapper in using Kendo UI. We basically want to just pass JSON back and forth between the client and server. If you have a sample project that we could view that demonstrates a client side approach that would be great.

    Thanks,
       Justin
      
  2. Daniel
    Admin
    Daniel avatar
    2117 posts

    Posted 26 Sep 2013 Link to this post

    Hello Justin,

    You should specify the contentType and set the request type to POST in order for the ModelBinder to bind the values:

    update: {
        url: 'Update',
        contentType: "application/json",
        type: "POST",
        dataType: 'json'
    }
    The parameterMap function should also be changed to convert the data to JSON for create and destroy as well.

    Regards,
    Daniel
    Telerik
    Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
  3. Kendo UI is VS 2017 Ready
  4. Justin
    Justin avatar
    3 posts
    Member since:
    Apr 2013

    Posted 01 Oct 2013 Link to this post

    Daniel,

         Thank you for your response. Unfortunately this did not resolve the issue, as we are still not able to pass the JSON into the update action method on the controller - still getting a null value.  The data/JSON is correct when the update operation is fired as I can see this debugging the Javascript. Am I missing something on the controller end? When selecting which variation of widgets to use (MVC server wrapper vs. client side) we went with client side. Because of this we do not have a view model to update from the fields being bound to the viewmodel. When you go this route how exactly is data sent back to the controller. I would assume this is JSON instead of accessing the viewmodel?

    -Justin
  5. Daniel
    Admin
    Daniel avatar
    2117 posts

    Posted 03 Oct 2013 Link to this post

    Hello again Justin,

    I attached a sample project that uses a ListView and posts the data as JSON. Please check it and let me know if you have any questions.
    I am not sure if I understand correctly your question about using a ViewModel. Could you clarify a bit?

    Regards,
    Daniel
    Telerik
    Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
  6. Justin
    Justin avatar
    3 posts
    Member since:
    Apr 2013

    Posted 07 Oct 2013 Link to this post

    Daniel,

    Ok - so I was way over thinking this and now have it working. Your example was helpful. Thanks!

    -Justin
Back to Top
Kendo UI is VS 2017 Ready