新手在这里..目前正在开发我的第一个 ASP.NET Web 应用程序。我正在尝试使用 SlickGrid。不知何故,网格根本没有出现,甚至没有显示标题:-(
下面是我的 Index.cshtml 代码:
@model IEnumerable<E_2.Models.DYE>
<link href="@Url.Content("~/Content/slick.grid.css")" rel="stylesheet" type="text/css" />
<script src="@Url.Content("~/Scripts/jquery.event.drag-2.0.min.js")" type="text/javascript"></script>
<script src="@Url.Content("~/Scripts/slick.core.js")" type="text/javascript"></script>
<script src="@Url.Content("~/Scripts/slick.grid.js")" type="text/javascript"></script>
<script src="@Url.Content("~/Scripts/SlickGridTest.js")" type="text/javascript">
</script>
@{
ViewBag.Title = "Index";
}
<h2>Index</h2>
<p>
@Html.ActionLink("Create New", "Create")
</p>
<table width="100">
<tr>
<td>
<div id="teamGrid" style="width:400px;height:300px;"></div>
</td>
</tr>
</table>
..这是我的 SlickGridTest.js 脚本
var grid;
var columns = [
{ id: "ID", name: "ID", field: "ID" },
{ id: "DESCRIPTION", name: "DESCRIPTION", field: "DESCRIPTION" },
];
var options = {
enableCellNavigation: true,
enableColumnReorder: false
};
$(function () {
var myData = [];
$.getJSON('/DYE/ReloadDyeData', function (data) {
myData = data;
grid = new Slick.Grid("#teamGrid", myData, columns, options);
});
..我的模型
using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
namespace E_2.Models
{
public partial class DYE
{
public int ID { get; set; }
[Required]
public string DESCRIPTION { get; set; }
[StringLength(3)]
public string COLOR_CODE { get; set; }
public Nullable<System.DateTime> VALID_UNTIL { get; set; }
}
}
* ..以及重新加载数据的控制器部分*
public string ReloadDyeData()
{
var dyes = db.DYEs.ToList();
JavaScriptSerializer serializer = new JavaScriptSerializer();
return serializer.Serialize(dyes);
}
由于缺乏这方面的 HTML、JavaScriot 和 ASP.NET 经验,我真的不知道根本问题在哪里。