コントローラーからのデータを表に印刷しようとしていますが、印刷できません。template
印刷するためにKendo UI を使用しています。発生しているエラーとともに、以下のコードを添付しています。
<div id="example"></div>
<script>
$.ajax(
{
type: 'POST',
url: '/default1/KendoDataAjaxHandle/',
dataType: 'json',
success: function (result) {
//Get the external template definition using a jQuery selector
var template = kendo.template($("#javascriptTemplate").html());
console.log(result);
var data = template(result); //Execute the template
$("#example").html(data); //Append the result
}
})
</script>
<script id="javascriptTemplate" type="text/x-kendo-template">
<table>
<thead>
<tr>
<th>Customer ID</th>
<th>Customer name</th>
<th>Gender</th>
</tr>
</thead>
<tbody>
# for (var i=0; i < result.length; i++){ #
<tr>
# for (var j=0; j < result[i].length; j++){ #
<td>
#= result[j] #
</td>
# } #
</tr>
# } #
</tbody>
</table>
</script>
上記のコードで行っていることは、アクション メソッドへの ajax 呼び出しを行い、JSON で結果を取得することです。これが私のコントローラーメソッドです:
public ActionResult KendoDataAjaxHandle([DataSourceRequest]DataSourceRequest request)
{
IQueryable<Customer> products = db.Customers;
DataSourceResult result = products.ToDataSourceResult(request);
return Json(result, JsonRequestBehavior.AllowGet);
}
コードの実行時に発生するエラーは次のとおりです。結果は未定義です。ただし、ajax 呼び出しの後に返された結果を慰めると、すべての値を持つオブジェクトを取得します。
テーブルに戻ってきた値を出力するにはどうすればよいですか? また、ここで何か間違ったことをした場合は修正してください。少し早いですがお礼を。