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

Functions aren't being executed in de datasource object initialisation...

2 Answers 70 Views
Data Source
This is a migrated thread and some comments may be shown as answers.
Eel
Top achievements
Rank 1
Eel asked on 10 Apr 2012, 10:17 AM
I have this code in the datasource initiliation:
new kendo.data.DataSource({
                        type: "odata",
                        transport: {
                            read: {
                                url: crudServiceBaseUrl + "/GetBrokersFromEvent()",
                                dataType: "jsonp",
                                data: {
                                    id: $("#input").data("kendoComboBox").value(),
                                    userid: e.data.adres
                                }
                            },
                            update: {
                                url: function(data) {
                                    return crudServiceBaseUrl + "/Brokers(" + data.ID + ")";
                                }

                            }
                            ,
                            create: {
                                url: crudServiceBaseUrl + "/Brokers"
                            },
                            destroy: {
                                url: function (data) {
                                    return crudServiceBaseUrl + "/Brokers(" + data.ID + ")";

                                }

                            }
                        }

The functions won't be exe"cuted, but instead they will ben pasted in the request url????

fiddler:
GET http://localhost/Admin/function%20(data)%20%7B%20%20%20%20return%20crudServiceBaseUrl%20+%20%22/Brokers(%22%20+%20data.ID%20+%20%22)%22;%7D?%24format=json&%24inlinecount=allpages&models%5B0%5D%5B__metadata%5D%5Buri%5D=http%3A%2F%2Flocalhost%2FAdmin%2FServices%2F%2FService.svc%2FBrokers(1916463)&models%5B0%5D%5B__metadata%5D%5Btype%5D...

What is going on?

2 Answers, 1 is accepted

Sort by
0
Eel
Top achievements
Rank 1
answered on 10 Apr 2012, 12:54 PM
Rewrote the code to MVC:

                        transport: {
                            read: {
                                url: "@Url.Action("GetBrokersFromEvent", "All")", /*specify the URL which should return the records. This is the Read method of the HomeController.*/
                                type: "POST", /*use HTTP POST request as by default GET is not allowed by ASP.NET MVC*/
                                data: {
                                    id: $("#input").data("kendoComboBox").value(),
                                    userid: e.data.adres
                                }
                            },
                            update: {
                                url:"@Url.Action("SaveBroker", "All")", /*specify the URL which should update the records. This is the Update method of the HomeController.*/
                                type: "POST" /*use HTTP POST request as by default GET is not allowed by ASP.NET MVC*/
                            },
                            parameterMap: function (data, operation) {
            if (operation != "read") {
               
                var result = {};

                for (var i = 0; i < data.models.length; i++) {
                    var broker = data.models[i];

                    for (var member in broker) {
                        result["broker[" + i + "]." + member] = broker[member];
                    }
                }

                return result;
            }

        }
                        },
                        batch: true,
                        pageSize: 10,


When I remove the parameterMap attribute, the read will work as aspected. But my update won't get the broker objects who are changed. Who can help me?
0
Eel
Top achievements
Rank 1
answered on 10 Apr 2012, 02:56 PM
Error in Firefox console:

The parameters dictionary contains a null entry for parameter 'id' of non-nullable type 'System.Int32' for method 'System.Web.Mvc.ActionResult GetBrokersFromEvent(Int32)' in 'ED.AdminWebsite.Controllers.AllianzController'. An optional parameter must be a reference type, a nullable type, or be declared as an optional parameter.<br>Parameter name: parameters</title>

Bug in Kendo:

when using parameterMap => data attribute on the read won't work

Tags
Data Source
Asked by
Eel
Top achievements
Rank 1
Answers by
Eel
Top achievements
Rank 1
Share this question
or