public async Task <IActionResult> ShowAllBranches(string search) { ViewData["data"] = search; var branches = _branch.GetAllBranches(); var model = _branch.GetAllBranches().Select(e => new ShowAllBranchesVM { branchID = e.BranchID, branchName = e.BranchName, city = _context.city.Where(x => x.CityID == e.CityID).Select(a => a.CityName).FirstOrDefault() }).ToList(); var query = from x in model select x; if (!String.IsNullOrEmpty(search)) { query = query.Where(x => x.city.Contains(search) || x.branchName.Contains(search)); } return(View(await query.ToListAsync())); }