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

ListView update issues

4 Answers 149 Views
ListView
This is a migrated thread and some comments may be shown as answers.
Justin
Top achievements
Rank 1
Justin asked on 24 Sep 2013, 10:12 PM
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
  

4 Answers, 1 is accepted

Sort by
0
Daniel
Telerik team
answered on 26 Sep 2013, 02:11 PM
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!
0
Justin
Top achievements
Rank 1
answered on 01 Oct 2013, 06:17 PM
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
0
Daniel
Telerik team
answered on 03 Oct 2013, 01:41 PM
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!
0
Justin
Top achievements
Rank 1
answered on 07 Oct 2013, 08:50 PM
Daniel,

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

-Justin
Tags
ListView
Asked by
Justin
Top achievements
Rank 1
Answers by
Daniel
Telerik team
Justin
Top achievements
Rank 1
Share this question
or