public static Select2PagedResult ToSelect2(this List <dynamic> pagedList, int totalListCount) { if (pagedList == null) { return(new Select2PagedResult()); } Select2PagedResult pagedResult = new Select2PagedResult(); pagedResult.Results = new List <Select2Result>(); //Loop through our list and translate it into a text value and an id for the select list foreach (dynamic a in pagedList) { if (a == null) { continue; } pagedResult.Results.Add(new Select2Result { id = a.UUID.ToString(), text = a.Name }); } //Set the total count of the results from the query. pagedResult.Total = totalListCount; return(pagedResult); }
//List<T> should be paginaged. //totalListCount is the listcount before the pagination split // public static Select2PagedResult ToSelect2 <T>(this List <T> pagedList, int totalListCount) { if (pagedList == null) { return(new Select2PagedResult()); } Select2PagedResult pagedResult = new Select2PagedResult(); pagedResult.Results = new List <Select2Result>(); //Loop through and translate it into a text value and an id for the select list // for (int i = 0; i <= pagedList.Count; i++) { Node a = null; try { a = (Node)Convert.ChangeType(pagedList[i], typeof(T)); } catch { continue; } if (a == null) { continue; } pagedResult.Results.Add(new Select2Result { id = a.UUID.ToString(), text = a.Name }); } //Set the total count of the results from the query. pagedResult.Total = totalListCount; return(pagedResult); }