javascript - Kendo ui grid dropdown editor does not load data -
can not load data kendo dropdown list. gets data backend list empty. backend looks like:
[httppost] public actionresult getcities(datasourcerequest command) { var citymodel = _uow.cities.getall().tolist(); var gridmodel = new datasourceresult { data = citymodel.select(preparecitymodelforlist), total = citymodel.count }; return json(gridmodel); }
front end
schema: { data: "data", total: "total", errors: "errors", model: { id: "id", fields: { name: { editable: true, type: "string" }, city: { defaultvalue: { cityid: 0, cityname: "select city" } }, address: { editable: true, type: "string" }, tel: { editable: true, type: "string" }, fax: { editable: true, type: "string" }, } } }, ...... columns: [... { field: "city.name", title: "city", editor: citydropdowneditor, template: "#=city.cityname#", width: 200 } .... function citydropdowneditor(container, options) { $('<input required data-text-field="cityname" data-value-field="cityid" data-bind="value:' + options.field + '"/>') .appendto(container) .kendodropdownlist({ autobind: false, datasource: { transport: { read: { url: "@html.raw(url.action("getcities", "contact"))", type: "post", datatype: "json" } } } }); }
the city model has cityname (string), cityid (int) , citypostalcode (string) fields. error in console "uncaught typeerror: e.slice not function"
upd* code preparecitymodelforlist
protected virtual companycitymodel preparecitymodelforlist(city city) { return new companycitymodel() { cityid = city.id, cityname = city.name, postalcode = city.postalcode }; }
upd*: returned json
{"extradata":null,"data":[{"cityid":3,"cityname":"minsk","postalcode":"220000"},{"cityid":4,"cityname":"brest","postalcode":"224000"},{"cityid":5,"cityname":"vitebsk","postalcode":"210000"},{"cityid":6,"cityname":"gomel","postalcode":"246000"}],"errors":null,"total":4}
the problem in json, passed ajax. have ensure json simple like:
{[ {"cityid":3,"cityname":"minsk","postalcode":"220000"}, "cityid":4,"cityname":"brest","postalcode":"224000"}, "cityid":5,"cityname":"vitebsk","postalcode":"210000"}, "cityid":6,"cityname":"gomel","postalcode":"246000"} ]}
Comments
Post a Comment