【发布时间】:2012-11-26 23:09:05
【问题描述】:
我有一个带有 jquery 数据表的视图,我想在一个按钮上立即使用另一个 Json 列表或他从控制器收到的任何数组重新填充表中的数据。
这是我认为的代码:
$.ajax({
type: "GET",
url: "EmpTruck/getJson/",
data: { search: station },
dataType: "Json",
error: function (xhr, status, error) {
alert(error);
},
success: function (json) {
alert(json.aaData);
var table = $(".dynamicTableEmployee").dataTable();
table.fnClearTable();
table.LoadDataRow(json);
}
});
这是来自控制器的代码:
[AcceptVerbs(HttpVerbs.Get)]
public JsonResult getJson()
{
List<Employees> list = new List<Employees>();
list = db.Employees.Where(c => c.Station.Equals("ATL")).ToList();
return this.Json(list, JsonRequestBehavior.AllowGet);
}
此代码仅清除数据表。 我已经设置了一个断点,看看Json数组中是否有东西。
我不知道如何从 json 数组中填充数据表,我需要序列化它吗? json需要和datatable一样大吗?
谢谢
【问题讨论】:
-
你能把你的代码添加到jsfiddle.net吗?
标签: c# jquery asp.net-mvc datatable