[英]Kendo UI Web - Grid Create/Update/Delete
I'm having an issue with Kendo UI Web & DataSource. 我在Kendo UI Web和数据源方面遇到问题。 Read works fine, I've serialized the database objects in JSON and I'm able to view them in the grid.
读取效果很好,我已经用JSON序列化了数据库对象,并且能够在网格中查看它们。 I need some pointers on how to get Create, Update & Delete working.
我需要一些有关如何使创建,更新和删除工作的指示。 I'm using the default MVC EF controller by the way.
顺便说一下,我正在使用默认的MVC EF控制器。
Is there a complete guide to set the grid up? 是否有完整的指南来设置网格? I've been looking but can't seem to find a suitable one.
我一直在寻找,但似乎找不到合适的人。
Please note that I can't use helpers since I'm using Kendo UI Web (which does not include helpers) 请注意,因为我使用的是Kendo UI Web(不包括帮助程序),所以我无法使用帮助程序。
您可以检查以下示例ASP.NET MVC项目: https : //github.com/telerik/kendo-examples-asp-net-mvc/tree/master/grid-crud
Update & Delete now work fine. 更新和删除现在可以正常工作了。 I switched over to using Web API and found it much simpler.
我转而使用Web API,发现它更加简单。 I followed the steps in this post.
我跟着步骤这个职位。 Only thing is, Create still won't work.
唯一的事情是,创建仍然行不通。 Upon further inspection, I noticed the id field was always blank during creation.
经过进一步检查,我发现id字段在创建过程中始终为空。
I'm subscribing to the following POST event in Web API: 我正在Web API中订阅以下POST事件:
// POST api/Categories
public HttpResponseMessage PostCategories(Categories categories)
{
if (ModelState.IsValid)
{
db.Categories.Add(categories);
db.SaveChanges();
HttpResponseMessage response = Request.CreateResponse(HttpStatusCode.Created, categories);
response.Headers.Location = new Uri(Url.Link("DefaultApi", new { id = categories.CategoryId }));
return response;
}
else
{
return Request.CreateResponse(HttpStatusCode.BadRequest);
}
}
Any idea how to fix this issue? 任何想法如何解决此问题?
Solved! 解决了! I changed the parameterMap function in the JS to the following and voila:
我将JS中的parameterMap函数更改为以下内容,瞧:
parameterMap: function (options, operation) {
if (operation == "create") {
return {
Category: options.Category
};
}
return options; }
Hope it helps anyone else out there who has the same issue. 希望它可以帮助其他有相同问题的人。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.