Asp.net mvc 5 在使用kendoGrid创建实体期间,WebApi v2 Odata的JayData行为不正确
这是我的控制器:Asp.net mvc 5 在使用kendoGrid创建实体期间,WebApi v2 Odata的JayData行为不正确,asp.net-mvc-5,kendo-grid,jaydata,asp.net-web-api-odata,Asp.net Mvc 5,Kendo Grid,Jaydata,Asp.net Web Api Odata,这是我的控制器: public class ProductEntityController : EntitySetController< ProductEntity, int> { public IQueryable< ProductEntity> Get(ODataQueryOptions< ProductEntity> parameters) { return productL
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) { });
为什么在保存之前调用innerInstance?
我如何解决我的问题?
我在MVC5上使用Jaydata1.3.6和剑道ui以及webApi2 Odata
请帮助我当我在客户端的创建模式下更改密钥字段ID的默认值时,出现了此问题。JayData将带有筛选器的GET请求发送到服务器。因此,由于我的实体上没有此Id,因此出现了和错误。然后将POST new实体发送到服务器。 结论:没有权限在kendoGrid中编辑您的密钥并在服务器上处理它
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);
});
}
});
}