0

I am trying to use use a datatable - from asp.net code to use as my source in my jquery Autocomplete. I am having difficulty in converting my table into a json format.

var resultItems = (from DataRow dr in dt.AsEnumerable()
                           select new SearchSerialResults
                           {
                               BeingSearched = (string)dr["BeingSearched"],
                               G017 = (string)dr["G017"],
                               G036 = (string)dr["G036"],
                               E017 = (string)dr["E017"]
                           }).ToList();
    var jsonObject = new
    {
        total = totalPages,
        pageSize,
        records = totalRecords,
        rows = (from SearchSerialResults item in resultItems
                select new
                {
                    id = item.G017,
                    cell = new[]
                    {
                        item.ContractLineItem.ToString(), 
                        item.BeingSearched,
                        item.G017,
                        item.G036,
                        item.E017,
                        ""
                    }
                }).ToArray()
    }; 
return Json(jsonObject) // for MVC
John Saunders
  • 160,644
  • 26
  • 247
  • 397

0 Answers0