public ActionResult ProductDetails(int id) { if (!isAdmin()) { return(RedirectToAction("LogIn", "Main")); } Product productDetails = _product.seeDetails(id); List <GroupedSelectListItem> dropdownsubcategory2 = new List <GroupedSelectListItem>(); var dropdownsubcategory1 = _product.getAllSubCategories(); foreach (var item in dropdownsubcategory1) { if (item.ID == productDetails.subCategoryid) { dropdownsubcategory2.Add(new GroupedSelectListItem() { GroupKey = item.catId.ToString(), GroupName = item.catName, Text = item.name, Value = item.ID.ToString(), Selected = true }); } else { dropdownsubcategory2.Add(new GroupedSelectListItem() { GroupKey = item.catId.ToString(), GroupName = item.catName, Text = item.name, Value = item.ID.ToString() }); } } IEnumerable <GroupedSelectListItem> dropdownsubcategory = dropdownsubcategory2; ProductDetail prodinfo = new ProductDetail() { itemnumber = productDetails.itemnumber, name = productDetails.name, description = productDetails.description, longDescription = productDetails.longDescription, price = productDetails.price, volum = productDetails.volum, countryid = productDetails.countryid, producerid = productDetails.producerid, pricePerLitre = productDetails.pricePerLitre, subCategoryList = dropdownsubcategory, countryList = _product.getCountries().Select(c => new SelectListItem { Value = c.id.ToString(), Text = c.name }).ToList(), producerList = _product.getProducers().Select(p => new SelectListItem { Value = p.id.ToString(), Text = p.name }).ToList() }; return(View(prodinfo)); }