我将信息从控制器传递到这样的视图:
return View(data);
如何在View中访问此数据以便数据绑定到KendoDataGrid? 我有以下代码:
@model IEnumerable<MyCustomerModel>
<div id="StatementGrid"></div>
<script>
$(document).ready(function() {
var lines = [{ TransactionDate: "01/01/2014", TransactionNumber: "001" }];//this works
var lines2 = @model //How to pass the model information here?
var grid = $("#StatementGrid").kendoGrid({
columns: [
{ field: "TransactionDate", title: "Date" },
{ field: "TransactionNumber", title: "Transaction Number" }
],
dataSource: {
data:lines
//data:lines2 //this does not work
}
});
});
</script>
答案 0 :(得分:0)
您可以 Json对您的模型进行编码,并将您的JavaScript行变量设置为等于该值,如下所示:
@model IEnumerable<MyCustomerModel>
<div id="StatementGrid"></div>
<script>
$(document).ready(function() {
var lines = @Html.Raw(Json.Encode(Model))
var grid = $("#StatementGrid").kendoGrid({
columns: [
{ field: "TransactionDate", title: "Date" },
{ field: "TransactionNumber", title: "Transaction Number" }
],
dataSource: {
data:lines
}
});
});
</script>
您必须设置日期数据类型和格式,但它会起作用。话虽这么说,我绝对不建议采用这种方法。相反,我会查看Telerik文档,了解如何使用以下链接使用远程或本地数据进行绑定,并遵循他们的指导: