public IActionResult Models(int brandId) { var carmodels = new List <CarModelViewModel>(); var model = new BrandViewModel(); try { var models = _brandApiCall.GetModelsByBrandId(brandId); var carBrand = _brandApiCall.GetT(brandId); for (int i = 0; i < models.Count(); i++) { bool canBeDeleted = true; if (models[i].BrandId.HasValue) { canBeDeleted = false; } carmodels.Add(new CarModelViewModel { Id = models[i].Id, BrandId = models[i].BrandId, Name = models[i].Name, CanBeDeleted = canBeDeleted }); } model.models = carmodels; model.Id = brandId; model.Name = carBrand.Name; try { ViewData["flag"] = (bool)TempData["SuccessResultF"]; ViewData["message"] = TempData["SuccessResultM"].ToString(); } catch (Exception) { } } catch (Exception) { throw; } return(View(model)); }