public async Task <IActionResult> EditAddress(string id, string currentFilter = null, string searchString = null, int?page = null) { if (searchString != null) { page = 1; } else { searchString = currentFilter; } ViewData["CurrentFilter"] = searchString; addresses.SearchString = searchString; addresses.PageIndex = page ?? 1; var devices = new AddressViewsList(null); if (!string.IsNullOrWhiteSpace(searchString)) { devices = new AddressViewsList(await addresses.GetDevicesList()); } var a = await addresses.GetObject(id) as GeographicAddress ?? new GeographicAddress(null); await deviceRegistrations.LoadDevices(a); var adr = AddressViewFactory.Create(a) as GeographicAddressView ?? new GeographicAddressView(); foreach (var device in adr.RegisteredTelecomAddresses) { devices.RemoveAll(x => x.Contact == device.Contact); } ViewBag.Devices = devices; return(View(adr)); }