剑道网格发布和删除将空值发送到控制器
Posted
技术标签:
【中文标题】剑道网格发布和删除将空值发送到控制器【英文标题】:Kendo grid post and delete send null to controller 【发布时间】:2013-02-02 10:04:17 【问题描述】:我正在发布一个 kendoui 网络网格,但它没有发送数据,我看不出我在做什么与失败的 sample 不同。我正在发布到控制器,但它是空的(如果批处理:true 或 null 如果批处理:false)
var crudServiceBaseUrl = "api/Certifications/",
dataSource = new kendo.data.DataSource(
transport:
read:
url: crudServiceBaseUrl + member.id,
dataType: "json"
,
update:
url: crudServiceBaseUrl,
type: "Post",
dataType: "json"
,
destroy:
url: crudServiceBaseUrl,
type: "Delete",
contentType: "application/json; charset=utf-8",
dataType: "json"
,
create:
url: crudServiceBaseUrl,
type: "Post",
dataType: "json"
,
parameterMap: function (options, operation)
if (operation !== "read" && options.models)
return models: kendo.stringify(options.models);
,
editable: //disables the deletion functionality
update: true,
destroy: true
,
batch: true,
pageSize: 30,
schema:
model:
id: "Id",
fields:
Id: editable: false, nullable: true ,
MemberId: editable: false, nullable: true ,
Name: validation: required: true ,
AuthorityName: validation: required: true ,
StartDate: type: "date", validation: required: true ,
EndDate: type: "date"
);
$("#certifications").kendoGrid(
dataSource: dataSource,
pageable: true,
height: 300,
toolbar: ["create"],
columns: [
field: "Name", title: "Product Name", width: 250 ,
field: "AuthorityName", title: "Authority", format: "0:c", width: "140px" ,
field: "StartDate", title: "Earned", template: '#= kendo.toString(StartDate,"MM/dd/yyyy") #', width: 50 ,
field: "EndDate", title: "Expired", template: '#= kendo.toString(EndDate,"MM/dd/yyyy") #', width: 50 ,
command: ["edit", "destroy"], title: " ", width: "130px" ],
editable: "popup"
);
网络 API:
public Certification DeleteCertification(CertificationVm cert)
var model = Uow.Certifications.Get(cert.Id);
if (model == null)
throw new HttpResponseException(new HttpResponseMessage(HttpStatusCode.NoContent));
Uow.Certifications.Delete(model);
Uow.Commit();
return model;
【问题讨论】:
你的问题很可能是***.com/questions/22622061/…,你可以在那里找到帮助 【参考方案1】:我想通了,虽然我不得不离开这个例子 http://demos.kendoui.com/web/grid/editing-popup.html
修复是添加内容类型,正确使用dataType:“json”,如上所述,从batch:true更改为batch:false并将参数映射更改为以下
destroy:
url: crudServiceBaseUrl,
type: "Delete",
contentType: "application/json; charset=utf-8",
dataType: "json"
,
parameterMap: function (model, operation)
if (operation !== "read" && model)
return kendo.stringify(model) ;
【讨论】:
【参考方案2】:没有像 jsonp + POST 这样的东西 - 讨论了here。 除非你真的知道为什么需要它,否则不要使用 jsonp。
【讨论】:
很好,你说得很对,我已经更正了我的例子,但删除方法配置正确。我确实想通了,离开后。然而,这不是答案。我将在下面发布正确答案。以上是关于剑道网格发布和删除将空值发送到控制器的主要内容,如果未能解决你的问题,请参考以下文章