【发布时间】:2015-01-25 14:58:51
【问题描述】:
我的 kendoUI 从不触发销毁方法?我究竟做错了什么。网格正确显示数据但未能删除记录。
$("#registration-grid").kendoGrid({
dataSource: {
type: "json",
transport: {
read: {
url: "@Html.Raw(Url.Action("List", "Participant"))",
type: "POST",
dataType: "json"
},
destroy: {
url: "http://localhost:53669/api/participant/",
type: "DELETE",
dataType: "json"
}
},
schema: { data: "Data", total: "Total", model: { id: "Id" } },
batch: false,
},
pageable: { ... },
editable: { mode: "inline" },
columns: [
{ field: "Id", title: "Id", width:50,filterable: false },
{ command: ["destroy"], title: " ", width: "250px" }
]
});
Web api 控制器参与者:在 fiddler /api/participant/delete/2 作品上测试
[HttpDelete]
public HttpResponseMessage Delete(int id)
{
var participant = _participantService.Get(p => p.Id == id);
if (participant == null)
return Request.CreateResponse(HttpStatusCode.BadRequest);
try
{
_participantService.Delete(participant);
return Request.CreateResponse(HttpStatusCode.OK);
}
catch (Exception)
{
return Request.CreateResponse(HttpStatusCode.BadRequest);
}
}
点击Delete 405 Method Not Allowed时KendoGrid显示错误,请求的资源不支持http方法'DELETE'
【问题讨论】:
-
尝试在控制器上将动词更改为 HttpPost 并在 html 中设置类型:“POST”。这里有一个例子demos.telerik.com/kendo-ui/grid/editing
-
最好的低成本解决方案是:将
httpdelete verb改为httppost动词
标签: asp.net-mvc kendo-ui telerik