1
我試圖讓Kendo UI網格在我的MVC3應用程序中連接,但我沒有收到任何數據顯示。我認爲這應該很簡單,但我沒有看到它。這裏是我的代碼:Kendo Grid plumbing
查看:
@model List<pests.web.com.Models.Workitem>
@{
ViewBag.Title = "Worklist";
ViewBag.CurrentPage = "Worklist";
}
<div id="grid"></div>
<script type="text/javascript">
$("#grid").kendoGrid({
dataSource: {
type: "json",
transport: {
read: {
url: "Home/GetWorklist",
dataType: "json",
type: "POST",
contentType: "application/json; charset=utf-8",
data: {}
}
},
columns: [
{
field: "PartNumber",
width: 90,
title: "Part Number"
},
{
field: "ProcurementCode",
width: 90,
title: "Procurement Code"
},
{
width: 100,
field: "Priority"
},
{
field: "Status"
}
]
}
});
</script>
<script type="text/javascript" src="../../Scripts/people.js"></script>
<script type="text/javascript" src="../../Scripts/kendo.web.min.js"></script>
<script type="text/javascript" src="../../Scripts/console.js"></script>
<link href="../../Styles/kendo.common.min.css" rel="stylesheet" />
<link href="../../Styles/kendo.default.min.css" rel="stylesheet" />
佈局頁:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>@ViewBag.Title</title>
<link href="@Url.Content("~/Styles/Site.css")" rel="stylesheet" type="text/css" />
<script src="@Url.Content("~/Scripts/jquery-1.5.1.min.js")" type="text/javascript"></script>
<script src="@Url.Content("~/Scripts/modernizr-1.7.min.js")" type="text/javascript"></script>
</head>
<body>
@RenderBody()
</body>
</html>
控制器代碼我試圖從視圖中撥打電話:
public class HomeController : Controller
{
[HttpPost]
public ActionResult GetWorklist()
{
List<Workitem> worklist = PestsLogic.GetWorklist();
return View("Home", worklist);
}
}
GetWorklist()正在返回幾件物品。它們是具有幾個屬性的簡單對象。這是它是:
public class Workitem
{
public string PartNumber { get; set; }
public string ProcurementCode { get; set; }
public int Priority { get; set; }
public string Status { get; set; }
}
有什麼明顯的,我已經迷上了錯誤?沒有錯誤信息,只是一個空白頁面(雖然有標題)。
謝謝!
也許你應該考慮使用$(document).ready,它應該確保在執行任何代碼之前加載腳本。 – Schalk 2012-11-23 11:36:54