我試圖用JSON數據或objects..whatever列表綁定jsGrid可能..jsgrid綁定MVC數據
$("#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);
}
OR
public ActionResult About(){
...
return View(students);
}
在json的情況下,我的網頁只顯示一個原始的json字符串,如果我返回一個lis t的學生對象,其他一切都在頁面上,但沒有網格。
我在做什麼錯了?
在附註中,我可以將這個網格與@Model綁定,就像我們在標記中一樣嗎?
登入網絡您收到的回覆是什麼。檢查模型屬性的外殼。關於「附註」是的,你可以。將數據綁定到表後,只需在該表上調用jqgird函數即可。 – User3250
我嘗試使用VAR值= @ Html.Raw(Json.Encode(Model.students)),它工作!現在我怎樣才能定義一個模板,以便除了上述4列之外,還可以動態添加x列? – Samra
您需要手動添加。 –