public ActionResult GetAutoCompleteData(string term) { hittafotbollsplanerEntities db = new hittafotbollsplanerEntities(); var result = db.fotbollsplaners.Where(x => x.Namn.Contains(term)) .Select(s => new FotbollsplanerAutocomplete { Value = s.Namn, Namn = s.Namn }) .Union(db.fotbollsplaners.Where(x => x.Adress.Contains(term)) .Select(s => new FotbollsplanerAutocomplete { Value = s.Adress, Namn = s.Adress })).ToList(); //List<FotbollsplanerAutocomplete> sorteradLista = result.OrderBy(o => o.Namn).ToList(); // SORTERAR LISTAN I NAMNORDNING //int index = 0; // KONTROLLERAR OM NAMNET ÄR DENSAMMA SOM // // NAMNET EFTERÅT. TAR I SÅ FALL BORT DUBLETTEN. //while (index < sorteradLista.Count - 1) // NÄR HELA LISTAN ÄR KLAR SÅ BLIR LISTAN REN. //{ // if (sorteradLista[index].Namn == sorteradLista[index + 1].Namn) // { // sorteradLista.RemoveAt(index); // } // else // { // index++; // } //} return(Json(result, JsonRequestBehavior.AllowGet)); }
public ActionResult Index() { hittafotbollsplanerEntities db = new hittafotbollsplanerEntities(); FotbollsplanerModels model = new FotbollsplanerModels(); List <fotbollsplaner> allaFotbollsplaner = db.fotbollsplaners.ToList(); model.AllaFotbollsplaner = allaFotbollsplaner; model.fotbollsplaner = allaFotbollsplaner.Take(7); // PLOCKAR UT 7 FRÅN LISTAN model.senasteFotbollsplaner = allaFotbollsplaner.OrderByDescending(o => o.Id).Take(7); // SORTERAR PÅ ID OCH // PLOCKAR UT 7 FRÅN LISTAN return(View(model)); }