public IActionResult Add(Product product) { int productGroupId; if (Int32.TryParse(Request.Form["productGroup"].ToString(), out productGroupId)) { product.ProductGroup = _productGroupLogic.Read(new ProductGroup { Id = productGroupId }).First(); } if (product.ProductGroup == null) { ModelState.AddModelError("ProductGroup", "Необходимо выбрать категорию товара."); } if (ModelState.IsValid) { _productLogic.CreateOrUpdate(product); return(RedirectToAction("Index")); } else { ViewBag.ProductGroups = GetProductGroups(product.ProductGroup != null ? product.ProductGroup.Id.Value : 1); return(View("Product", product)); } }