public ActionResult Create(int id, FormCollection form, string filter) { try { using (var context = new CatalogueContainer()) { var category = context.Category.First(c => c.Id == id); var brand = new Brand { Category = category }; PostCheckboxesData cbData = form.ProcessPostCheckboxesData("attr"); foreach (var kvp in cbData) { var attrId = kvp.Key; bool attrValue = kvp.Value; if (attrValue) { var attribute = context.CategoryAttribute.First(c => c.Id == attrId); brand.CategoryAttributes.Add(attribute); } } TryUpdateModel(brand, new[] { "Title", "Name", "SortOrder", "Href", "DescriptionTitle" }); brand.Name = brand.Name.ToLower().Replace(" ", ""); brand.Description = HttpUtility.HtmlDecode(form["Description"]); context.AddToBrand(brand); context.SaveChanges(); return RedirectToAction("Index", "Catalogue", new { area = "", category = category.Name, filter=filter }); } } catch { return View(); } }