//gets/reads all equipment, used for dropdown list public ActionResult GetEquipment() { //stores the first table Equipment = itsApp.GetEquipment().Tables[0].DefaultView; //serializes/converts the DataView to JSON JavaScriptSerializer jsSerializer = new JavaScriptSerializer(); List <Dictionary <string, object> > parentRow = new List <Dictionary <string, object> >(); Dictionary <string, object> childRow; foreach (DataRow row in Equipment.Table.Rows) { childRow = new Dictionary <string, object>(); foreach (DataColumn col in Equipment.Table.Columns) { childRow.Add(col.ColumnName, row[col]); } parentRow.Add(childRow); } //takes the List, and filters through to data using LINQ to SQL format, //gets only the rows of data that have Activity labeled as "true" //var equipmentTableFilteredByActiveTrue = from x in parentRow // where x.Keys.Contains("Active") // && x.Values.Contains(true) // select x; //serialized the data into javascript //string JsSerializer = JsonConvert.SerializeObject(equipmentTableFilteredByActiveTrue); string JsSerializer = JsonConvert.SerializeObject(parentRow); //this sets the Json data allowance to it's max value. Otherwise, Json will limit the Equipment data from displaying JsonResult json = Json(JsSerializer, JsonRequestBehavior.AllowGet); json.MaxJsonLength = int.MaxValue; return(json); }
//gets/reads all equipment from GetEquipment method, filtered by 'E' used for dropdown list public ActionResult GetEquipment() { //stores the first table EquipmentNumbers = itsApp.GetEquipment().Tables[0].DefaultView; //variable to serialize/convert the List to JSON JavaScriptSerializer jsSerializer = new JavaScriptSerializer(); //serializes the data of the DataView into a List of key-value pairs List <Dictionary <string, object> > parentRow = new List <Dictionary <string, object> >(); Dictionary <string, object> childRow; foreach (DataRow row in EquipmentNumbers.Table.Rows) //foreach row in the table { childRow = new Dictionary <string, object>(); //creates a new dictionary of childrow foreach (DataColumn col in EquipmentNumbers.Table.Columns) //foreach childrow, add it to the parent master object { childRow.Add(col.ColumnName, row[col]); } parentRow.Add(childRow); } //takes the List, and filters through to data using LINQ to SQL format, //gets only the rows of data that are labeled as being an Equipment i.e. "E" type var equipmentTableFilteredByE = from x in parentRow where x.Keys.Contains("EquipmentOrImplement") && x.Values.Contains("E") select x; //serialized the data into javascript, replaces the "\" escape character string JsSerializer = JsonConvert.SerializeObject(equipmentTableFilteredByE); //this sets the Json data allowance to it's max value. Otherwise, Json will limit the Equipment data from displaying JsonResult json = Json(JsSerializer, JsonRequestBehavior.AllowGet); json.MaxJsonLength = int.MaxValue; return(json); }