1

这是我的控制器:

 public class ProductEntityController : EntitySetController<
 ProductEntity, int> 
     { 
         public IQueryable< ProductEntity> Get(ODataQueryOptions< ProductEntity> parameters)
         {
             return productList.AsQueryable();
         }
         public  ProductEntity Create(ProductEntity entity)
         {
             productList.Add(entity);

             return entity;
         } }

//---------------------------------------

this my JS code:



 var context = new $data.initService('/odata');
      context.then(function (db) {

      var dsD = db.ProductEntity.asKendoDataSource();

      grid=  $('#gridD').kendoGrid({
                 dataSource: dsD,
                 filterable: true,
                 sortable: true,
                 pageable: true,
                 selectable: true,
                 height: 400,
                 columns: [
                     { field: 'Name' },
                     { field: 'Created' },
                     { field: 'Index' },
                     { field: 'LargeNum' },
                     { command: ["edit", "destroy", "update"] }
                 ],
                 toolbar: ["create", "save", "cancel"],
                 editable: "inline"

           }).data("kendoGrid");


         }).fail(function (args) {  });

//-------- 当我“添加新记录”或“保存更改”时,两个请求被发送到服务器(GET 和 POST)。

我有一个错误:'result count failed ' at GET Response.

我在以下代码中发现了一个问题kendo.js

  create: function (options, model) {
     var query = self;
     query.entityContext.onReady().then(function () {
     if (model.length > 1) {
     ..............
     ..........
     }
     else {
     console.dir(ctx.storeToken);
     model[0]
     .innerInstance() // when i comment this line everything is gonna be ok

     .save(ctx.storeToken)
     .then(function () {
     options.success();
     })
     .fail(function () {
     console.log("error in create");
     options.error({}, arguments);
     });
     }
     });
     }

为什么innerInstance()在保存之前调用?我该如何解决我的问题?我Jaydata 1.3.6在 MVC 5 上使用剑道 ui 和 webApi2 Odata 请帮助我

4

1 回答 1

0

当我在客户端的创建模式下更改键字段(Id)的默认值时发生此问题。JayData 将带有过滤器的 GET 请求发送到服务器。因此我有错误,因为我的实体上没有此 ID。然后将 POST 新实体发送到服务器。结论:无权在 kendoGrid 中编辑您的密钥并在服务器上处理它。

于 2014-06-11T12:12:27.070 回答