We are using the grid in a MVC app. I can get the Read, Update and Delete functions to work without issue. However every time we try to do an insert the entity being passed to the controller is null. Here is the code:
OData Controller:
Index.cshtml:
I have found tons of articles and examples using the ActionLinks, but nothing that would seem to tell me why this call to Create would not work.
Thanks for any help you can provide.
Chuck
OData Controller:
protected
override
BroadcastEventViewModel CreateEntity(BroadcastEventViewModel entity)
{
var bcEvent =
new
Model.BroadcastEvent()
{
Id = entity.Id,
Name = entity.Name,
StartDate = entity.StartDate,
EndDate = entity.EndDate
};
_repository.InsertBroadcastEvent(bcEvent);
return
entity;
}
var
crudServiceBaseUrl =
"/odata/BroadcastEvents"
;
var
pledgesModel = kendo.observable({
dataSource: broadcastEventDataSource =
new
kendo.data.DataSource({
type:
"odata"
,
transport: {
create: {
url: crudServiceBaseUrl,
dataType:
"json"
,
},
read: {
url: crudServiceBaseUrl,
dataType:
"json"
},
update: {
url:
function
(data) {
return
crudServiceBaseUrl +
"("
+ data.Id +
")"
;
},
dataType:
"json"
},
destroy: {
url:
function
(data) {
return
crudServiceBaseUrl +
"("
+ data.Id +
")"
;
},
dataType:
"json"
}
},
batch:
false
,
serverPaging:
true
,
serverSorting:
true
,
serverFiltering:
true
,
pageSize: 5,
schema: {
data:
function
(data) {
return
data.value;
},
total:
function
(data) {
return
data[
"odata.count"
];
},
errors:
function
(data) {
},
model: {
id:
"Id"
,
fields: {
Id: { type:
"number"
, editable:
false
, nullable:
true
},
Name: { type:
"string"
},
StartDate: { type:
"datetime"
},
EndDate: { type:
"datetime"
},
}
}
},
error:
function
(e) {
var
response = e.xhr.responseJSON;
var
message = response.Message;
//if (e.xhr.responseJSON["odata.error"].Message != null) {
// message = e.xhr.responseJSON["odata.error"].Message;
//}
alert(message +
"\n\n"
);
}
})
});
$(
"#broadcastEventGrid"
).kendoGrid({
dataSource: broadcastEventDataSource,
toolbar: [
"create"
,
"save"
,
"cancel"
],
sortable:
false
,
pageable:
true
,
filterable:
false
,
columns: [
{ field:
"Id"
, title:
"ID"
, width: 150 },
{ field:
"Name"
, title:
"Name"
, width: 200 },
{ field:
"StartDate"
, title:
"Start Date"
, width: 200 },
{ field:
"EndDate"
, title:
"End Date"
, width: 200 },
{
command: [
"edit"
, {
name:
"Details"
,
click:
function
(e) {
// var tr = $(e.target).closest("tr");
//var data = this.dataItem(tr);
alert(
"Details for: "
+ e.target);
}
}], title:
"Action"
,
}
],
editable: {
createAt:
"bottom"
,
mode:
"inline"
}
});
Thanks for any help you can provide.
Chuck