public ActionResult ProductDetails(int id, ProductDetail p) { if (!isAdmin()) { return(RedirectToAction("LogIn", "Main")); } if (ModelState.IsValid) { Product updated = new Product() { itemnumber = p.itemnumber, name = p.name, description = p.description, longDescription = p.longDescription, price = p.price, countryid = p.countryid, subCategoryid = p.subCategoryid, volum = p.volum, producerid = p.producerid }; Customer admin = (Customer)Session["loggedInUser"]; var adminid = admin.id; bool result = _product.updateProduct(adminid, updated); List <GroupedSelectListItem> test2 = new List <GroupedSelectListItem>(); var test1 = _product.getAllSubCategories(); foreach (var item in test1) { if (item.ID == p.subCategoryid) { test2.Add(new GroupedSelectListItem() { GroupKey = item.catId.ToString(), GroupName = item.catName, Text = item.name, Value = item.ID.ToString(), Selected = true }); } else { test2.Add(new GroupedSelectListItem() { GroupKey = item.catId.ToString(), GroupName = item.catName, Text = item.name, Value = item.ID.ToString() }); } } IEnumerable <GroupedSelectListItem> test = test2; p.countryList = _product.getCountries().Select(c => new SelectListItem { Value = c.id.ToString(), Text = c.name }).ToList(); p.subCategoryList = test; p.producerList = _product.getProducers().Select(r => new SelectListItem { Value = r.id.ToString(), Text = r.name }).ToList(); if (result) { return(Json(new { success = true, message = "Endringene ble lagret", redirect = "/Product/ListProducts/" })); } return(Json(new { success = false, message = "Noe gikk galt, prøv igjen" })); } return(Json(new { success = false, message = "Feil i validering" })); }