【发布时间】:2017-05-30 01:46:53
【问题描述】:
我正在尝试将 jsGrid 与 json 数据或对象列表绑定..任何可能的..
$("#mapsDiv").jsGrid({
height: "auto",
width: "100%",
sorting: true,
paging: false,
autoload: true,
data: students,
controller: {
loadData: function () {
var d = $.Deferred();
$.ajax({
url: '@Url.Action("About", "Home")',
dataType: "json"
}).done(function (response) {
d.resolve(response.value);
});
return d.promise();
}
},
fields: [
{ name: "firstname", type: "text" },
{ name: "surname", type: "text"},
{
name: "birthdate", type: "text"
},
{
name: "classname", type: "text"
}
]
});
HomeController
public ActionResult About(){
...
return Json(students, JsonRequestBehavior.AllowGet);
}
或
public ActionResult About(){
...
return View(students);
}
如果是 json,我的网页只显示原始 json 字符串,如果我返回学生对象列表,其他所有内容都在页面上但没有网格。
我做错了什么?
顺便说一句,我可以像在标记中那样将此网格与@Model 绑定吗?
【问题讨论】:
-
检查网络您得到的响应是什么。检查模型属性的外壳。关于“旁注”是的,你可以。将数据绑定到表后,只需在该表上调用 jqgird 函数。
-
我尝试使用 var values = @Html.Raw(Json.Encode(Model.students)),效果很好!!现在我该如何定义一个模板,以便它可以在上述 4 列之外动态添加 x 列?
-
您需要手动添加。
-
@Samra 不确定我的回答 here 是否有帮助
标签: json asp.net-mvc jsgrid