public ActionResult Create(Title model) { string view = "Create"; if (!string.IsNullOrEmpty(model.Publisher.PublisherID)) { model.Publisher = _pubsService.GetPublisher(model.Publisher.PublisherID); ModelState.Clear(); TryValidateModel(model); } if (_addAuthorFeature.FeatureEnabled) { view = "Create2"; // Construct authors collection if (model.Authors == null) { model.Authors = new List <Author>(); } else { model.Authors.Clear(); } List <Author> authors = _pubsService.ListAuthors(); foreach (Author a in authors) { if (Request.Form[string.Format("author-{0}", a.AuthorID)] != null) { model.Authors.Add(a); } } } // Custom validation if (model.Advance > (((decimal)model.Royalty / 100) * 10000)) { ModelState.AddModelError("Advance", "Advance is too large"); } if (ModelState.IsValid) { _pubsService.CreateTitle(model); TempData["Message"] = "Title added!"; return(RedirectToAction("Index")); } // There were model errors List <Publisher> publishers = _pubsService.ListPublishers(); ViewBag.Authors = _pubsService.ListAuthors(); ViewBag.Publishers = new SelectList(publishers, "PublisherID", "Name", model.Publisher.PublisherID); return(View(view, model)); }