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

Accessing kendoDropDownList object for PUT

1 Answer 68 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Brent
Top achievements
Rank 1
Brent asked on 15 Sep 2015, 04:40 PM

I am currently using WebAPI and KendoUI (drop down in this example). When I need to the object to the API I grab the object out of the data source. To get the selected item I use:

var ​dataItem= $("#dropDown").data("kendoDropDownList").dataItem();

Then to make the object valid I have to remove kendo's ID like so:

delete dataItem.$id

After this I can JSON.stringify the object to pass to the API via ajax:

$.ajax({
    type: "PUT",
    url: BASE + "Api/MyController",
    data: JSON.stringify(dataItem),
    contentType: "application/json",
    success: function () {
        alert("Success");
    },
    error: function (result) {
        alert("failed");
    }
});​

 

Is this bad practice? Is there a better way of getting the object from the data source instead of deleting kendoui's $id every time?

1 Answer, 1 is accepted

Sort by
0
Kiril Nikolov
Telerik team
answered on 17 Sep 2015, 07:55 AM

Hello Brent,

The dataItem() method will always return the full data item including the ID. There is no method that will return the dataItem without the ID field unfortunately. 

Regards,
Kiril Nikolov
Telerik
 
Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
 
Tags
Grid
Asked by
Brent
Top achievements
Rank 1
Answers by
Kiril Nikolov
Telerik team
Share this question
or