public ActionResult AddVersion(VersionViewModel version) { string error = null; if(TryValidateModel(version)) { Product product = _productRepository.Find(version.ProductId); product.Versions.Add(new Version { Name = version.Name, IamRole = version.IamRole}); _productRepository.Update(product); } else { error = ModelState.SelectMany(x => x.Value.Errors).First().ErrorMessage; } return RedirectToAction("Index", new {productId = version.ProductId, error}); }
public ActionResult AddVersion(Guid productId, string error = null) { if(error != null) { ModelState.AddModelError("", error); } var model = new VersionViewModel {ProductId = productId}; return View(model); }