1
我在ASP.NET MVC,Entity Framework和OData中使用Kendo UI Grid。 我也有網格中的記錄ID - 迄今爲止非常好。Kendo UI Grid - 添加新記錄顯示0爲ID
但是,當我點擊工具欄上的「添加新的歷史記錄」的ID列顯示了我,而我編輯的數據爲0。
我點擊「更新」按鈕,它不更改爲正確的ID(已服務返回)後:
{
"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"
}
當我刷新頁面/瀏覽器正確的ID被顯示。
這裏是我的POST方法:
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;
}
而這裏的數據源JS(的一部分):
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"
}