odata - Kendo UI Grid - Add new record shows 0 as ID -
i'm using kendo ui grid asp.net mvc, entity framework , odata. have record id inside grid - far good.
but when click on "add new record" in toolbar id column shows me 0 while i'm editing data.
and after click on "update" button doesn't change correct id (which has been returned service):
{ "odata.metadata":"http://localhost:61534/api/$metadata#assetlist/@element", "id":17, "manufacturername":"test", "name":"test", "serialnumber":"test", "assetstateid":1, "assetstatename":"test", "nextcalibration":"2013-07-11t09:08:28.298z" }
when refresh page/browser correct id shown.
here's post method:
public override httpresponsemessage post(assetlistviewmodel item) { // #### mg: create asset rsams.webui.models.asset asset = new asset(); asset.manufacturer = item.manufacturername; asset.name = item.name; asset.serialnumber = item.serialnumber; asset.assetstateid = 1; // in use asset.nextcalibration = item.nextcalibration; db.asset.add(asset); db.savechanges(); // #### mg: response item.id = asset.id; item.assetstateid = asset.assetstateid; var response = request.createresponse<assetlistviewmodel>(httpstatuscode.created, item); response.headers.location = new uri(url.link("odata", new { id = item.id })); return response; }
and here's datasource js (part of it):
datasource: { type: "odata", pagesize: 25, serversorting: true, serverpaging: true, transport: { create: { url: "/api/assetlist", datatype: "json" }, read: { url: "/api/assetlist", datatype: "json" }, update: { url: "/api/assetlist", datatype: "json" }, destroy: { url: function (data) { return "/api/assetlist([rw-param])".replace("[rw-param]", data.id); }, datatype: "json" }
the field display "0" text, because default value of "recordid " property (this default behavior). supports setting value after data retrieved.what can clear value manually:
function ongridedit(e) { if (e.model.isnew()) { e.model.set("recordid", null); } }
this code needs placed in grid edit event handler.
Comments
Post a Comment