I'm trying to add some items to a Kendo DataSource to then display in the grid. However, every time I try to save I get Reference Error: Id is not defined.
001.
var
viewModel =
new
kendo.observable({
002.
orgDataSource:
new
kendo.data.DataSource({
003.
transport: {
004.
read: {
005.
url:
"/Organization/GetAll"
,
006.
dataType:
"json"
007.
},
008.
update: {
009.
url:
"/Host/Organization/Edit"
,
010.
dataType:
"json"
,
011.
type:
"POST"
,
012.
data: {
013.
__RequestVerificationToken: getAntiForgeryToken()
014.
}
015.
},
016.
create: {
017.
url:
"/Host/Organization/Create"
,
018.
dataType:
"json"
,
019.
type:
"POST"
,
020.
data: {
021.
__RequestVerificationToken: getAntiForgeryToken()
022.
}
023.
},
024.
destroy: {
025.
url:
"/Host/Organization/Delete"
,
026.
dataType:
"json"
,
027.
type:
"POST"
,
028.
data: {
029.
__RequestVerificationToken: getAntiForgeryToken()
030.
}
031.
}
032.
},
033.
schema: {
034.
model: {
035.
id:
"Id"
,
036.
fields: {
037.
Id: { type:
"number"
, editable:
false
, nullable:
true
},
038.
Name: { type:
"string"
},
039.
LicenseExpiration: { type:
"date"
},
040.
LicenseNumber: { type:
"number"
},
041.
Active: { type:
"boolean"
},
042.
CreateDate: { type:
"date"
},
043.
LastModDate: { type:
"date"
},
044.
AvailableLicenses: { type:
"string"
},
045.
State: { type:
"string"
}
046.
}
047.
},
048.
errors:
"errorMsg"
049.
},
050.
pageSize: 20,
051.
error:
function
(e) {
052.
toastr.options = {
053.
"positionClass"
:
"toast-bottom-full-width"
054.
};
055.
toastr.error(
"There was an error: "
+ e.errors,
"Uh, Oh!"
);
056.
this
.cancelChanges();
057.
},
058.
serverPaging:
false
,
059.
serverFiltering:
false
,
060.
serverSorting:
false
061.
}),
062.
reloadOrganizations:
function
() {
063.
this
.get(
"orgDataSource"
).read();
064.
},
065.
onOrgSave:
function
(e)
066.
{
067.
var
uid = $(
'input[name="OrgRowUID"]'
).val();
068.
var
tr = $(
'tr[data-uid="'
+ uid +
'"]'
);
// get the current table row (tr)
069.
var
name = $(
'input[name="Name"]'
).val();
070.
var
licenseNumber = $(
'input[name="LicenseNumber"]'
).val();
071.
var
licenseExpiration = $(
'input[name="LicenseExpiration"]'
).val();
072.
var
email = $(
'input[name="Email"]'
).val();
073.
var
state = $(
'input[name="State"]'
).val();
074.
var
logo = $(
'input[name="ImageUrl]'
).val();
075.
var
active = $(
'input[name="Active"]'
).is(
":checked"
);
076.
077.
// get the data bound to the current table row
078.
var
orgGrid = $(
"#OrganizationGrid"
).data(
"kendoGrid"
);
079.
var
data = orgGrid.dataItem(tr);
080.
081.
if
(data ==
null
)
082.
{
083.
viewModel.orgDataSource.add({ Name: name, LicenseNumber: licenseNumber, LicenseExpiration: licenseExpiration, Email: email, State: state, ImageUrl: logo, Active: active })
084.
orgGrid.saveChanges();
085.
viewModel.orgDataSource.sync();
086.
viewModel.reloadOrganizations();
087.
}
else
{
088.
data.set(
"Name"
, name);
089.
data.set(
"LicenseNumber"
, licenseNumber);
090.
data.set(
"LicenseExpiration"
, licenseExpiration);
091.
data.set(
"Email"
, email);
092.
data.set(
"State"
, state);
093.
data.set(
"ImageUrl"
, logo);
094.
data.set(
"Active"
, active);
095.
}
096.
097.
$(
"#orgCreateModal"
).modal(
'hide'
);
098.
$(
"#orgEditModal"
).modal(
'hide'
);
099.
}
100.
});
The error is occurring on this line:
viewModel.orgDataSource.add({ Name: name, LicenseNumber: licenseNumber, LicenseExpiration: licenseExpiration, Email: email, State: state, ImageUrl: logo, Active: active });
The error in FireBug is:
"Reference Error: Id is not defined - kendo.all.min.js line 25 > function"
I basically just copied this code from another grid that I created and it works perfectly fine on the other one. So I'm not sure what I'm missing here that is causing this error.