我有一个问题,即JQGrid加载数据但显示空记录。这是我的控制器操作方法:
public ActionResult Database(string server,string database, string username, string password)
{
UserAthentication U = new UserAthentication();
U.ServerName = server;
U.DatabaseName = database;
U.Username = username;
U.Password = password;
Database db = new Database();
var Names = db.GetDatabaseNames(U); //This method returns the string list and i debugged it it returns the data correctly.
var jsondata = new
{
total = 1,
page = 1,
records = 0,
rows = Names
};
return Json(jsondata, JsonRequestBehavior.AllowGet);
}
这是JQgrid代码:
$(document).ready(function () {
$('#b1').click(function () {
var server = $("#ServerName").val();
var database = $("#DatabaseName").val();
var username = $("#Username").val();
var password = $("#Password").val();
var URL = '/Home/Database?server=' + server+"&database="+database+"&username="+username+"&password="+password;
$("#Grid").jqGrid({
url: URL,
datatype: 'json',
colNames: ['Tables Name'],
colModel: [
{ name: 'TABLE_NAME', index: 'TABLE_NAME' },
],
jsonReader: {
root: 'rows',
page: 'page',
total: 'total',
records: 'records',
repeatitems: false
},
pager: $('#pager'),
rowNum: 10,
rowList: [10, 20, 30],
width: 600,
viewrecords: true,
emptyrecords: 'No records to display',
sortorder: "desc",
caption: 'Databases',
loadonce: false,
});
});
});
答案 0 :(得分:0)
colModel: [
{ name: 'TABLE_NAME', index: 'TABLE_NAME' },
],
您不使用TABLE_NAME,而是使用这样的列名:
colModel: [
{ name: 'Column_NAME', index: 'Column_NAME' },
{ name: 'Column_NAME', index: 'Column_NAME' },
{ name: 'Column_NAME', index: 'Column_NAME' },
{ name: 'Column_NAME', index: 'Column_NAME' },
],