I have Kendo UI Professional and I am trying to create a KendoGrid using data from the ViewData.Model
My script looks like this:
@model IEnumerable<WebApplication5.Models.Presentation>
..
<script>
$(document).ready(function () {
var dataSource = new kendo.data.DataSource({
pageSize: 21,
data: @Model,
dataType: JSON,
schema: {
model: {
fields: {
Name: {},
PresentationFamilyId: {},
SourcePresentationId: {}
}
}
}
});
$("#grid").kendoGrid({
dataSource: dataSource,
height: 550,
groupable: true,
sortable: true,
pageable: {
refresh: true,
pageSizes: true,
buttonCount: 5
},
columns: [{
field:"Name",
title:"Name"
}, {
field:"PresentationFamilyID",
title:"Family"
}, {
field:"SourcePresentationID",
title:"Source"
}]
});
});
</script>
My
controller looks like this:
public ActionResult Index()
{
return View(db.Presentations);
}
I cannot get it to work. I have tried every permutation for DataSource.data that I can think of
but they all generate errors. For instance, the above code complains about “Unexpected token ]”
Tried in controller: return View(db.Presentations.ToArray()); -- Unexpected Token ]
Changed javascript:
data: @Model.ToArray() -- Unexpected Token ]
data: @Model.ToList()
– The browser shows: data: System.Collections.Generic.List`1[WebApplication5.Models.Presentation],
with error:
Unterminated template literal
(this is because of the unmatched quote mark)
How do I
specify @Model as my datasource?