public JsonResult getDistrictServerSide(string searchTerm, int pageSize, int pageNum, int page) { //Get the paged results and the total count of the results for this query. List <District> districts = unitOfWork.BusinessEntityRepository.DistrictRepository.GetDistricts(searchTerm, pageSize, pageNum); int Count = unitOfWork.BusinessEntityRepository.DistrictRepository.GetDistrictsCount(searchTerm, pageSize, pageNum); //Translate the attendees into a format the select2 dropdown expects Select2PagedResult Data = AttendeesToSelect2Format(districts, Count); //Return the data as a jsonp result return(Json(Data, JsonRequestBehavior.AllowGet)); }
private Select2PagedResult AttendeesToSelect2Format(List <District> attendees, int totalAttendees) { Select2PagedResult jsonAttendees = new Select2PagedResult(); jsonAttendees.Results = new List <Select2Result>(); //Loop through our attendees and translate it into a text value and an id for the select list foreach (District a in attendees) { jsonAttendees.Results.Add(new Select2Result { id = a.DistrictID.ToString(), text = a.DistrictName }); } //Set the total count of the results from the query. jsonAttendees.Total = totalAttendees; return(jsonAttendees); }