我有一个json就是这样:
var jsonData = new
{
total = totalPages,
page = page,
records = totalRecords,
rows = reservations.Select(x => new { x.ReservationId, x.Employee.Name,roomName = x.Room.Name, x.Date, x.StartTime, x.EndTime, x.Notes}).ToList()
.Select(x => new
{
id = x.ReservationId,
cell = new string[]
{
roomName,
x.Name,
x.Date.ToString().Split(' ')[0],
x.StartTime.ToString().Remove(5) +" - " +x.EndTime.ToString().Remove(5),
x.Notes,
String.Format("<input type=\"button\" value=\"DETAILS\" onclick=\"window.location.href='/Reservation/Details/{0}'\"/>   <input type=\"button\" value=\"EDIT\" onclick=\"window.location.href='/Reservation/Edit/{0}'\"/>   <input type=\"button\" value=\"DELETE\" onclick=\"window.location.href='/Reservation/Delete/{0}'\"/>", x.ReservationId),
}
}).ToArray(),
};
这个json将返回到jqGrid。当我在第一个select语句中键入x.Room.Name时,由于已存在具有相同名称的属性(即x.Employee.Name)而发生错误。
所以我尝试了“roomName = x.Room.Name”并将roomName放入单元格内容中。
但是,当json返回到我的jqGrid时,该列(可能包含roomName)为空。我怎么能以其他方式显示x.Room.Name的值?
答案 0 :(得分:1)
由于您已将列重命名为roomName
,请确保在客户端上有相应的列:
$('#grid').jqGrid({
colNames: [ 'roomName', 'Name', ..... other columns ],
colModel: [
{ name: 'roomName', index: 'roomName' },
{ name: 'Name', index: 'Name' },
.....
],
........
});