Don't like ads? PRO users don't see any ads ;-)
Guest

Untitled

By: a guest on Jul 24th, 2012  |  syntax: None  |  size: 1.37 KB  |  hits: 23  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. linq and json, anonymous type cannot have multiple properties with the same name
  2. var jsonData = new
  3.         {
  4.             total = totalPages,
  5.             page = page,
  6.             records = totalRecords,
  7.             rows = reservations.Select(x => new { x.ReservationId, x.Employee.Name,roomName = x.Room.Name, x.Date, x.StartTime, x.EndTime, x.Notes}).ToList()
  8.                 .Select(x => new
  9.                 {
  10.                     id = x.ReservationId,
  11.                     cell = new string[]
  12.                     {
  13.                     roomName,
  14.                     x.Name,
  15.                     x.Date.ToString().Split(' ')[0],
  16.                     x.StartTime.ToString().Remove(5) +" - " +x.EndTime.ToString().Remove(5),
  17.                     x.Notes,
  18.                     String.Format("<input type="button" value="DETAILS" onclick="window.location.href='/Reservation/Details/{0}'"/>&nbsp &nbsp<input type="button" value="EDIT" onclick="window.location.href='/Reservation/Edit/{0}'"/>&nbsp &nbsp<input type="button" value="DELETE" onclick="window.location.href='/Reservation/Delete/{0}'"/>", x.ReservationId),
  19.                     }
  20.                 }).ToArray(),
  21.         };
  22.        
  23. $('#grid').jqGrid({
  24.     colNames: [ 'roomName', 'Name', ..... other columns ],
  25.     colModel: [
  26.         { name: 'roomName', index: 'roomName' },
  27.         { name: 'Name', index: 'Name' },
  28.         .....
  29.     ],
  30.     ........
  31. });