public ActionResult Create([Bind(Include = "ProductID,Name,ProductNumber,Color,StandardCost,ListPrice,Size,Weight,CategoryID,ProductModelID,SellStartDate,SellEndDate,DiscontinuedDate,ThumbNailPhoto,ThumbnailPhotoFileName,rowguid,ModifiedDate")] Product product) { if (ModelState.IsValid) { db.Products.Add(product); db.SaveChanges(); return(RedirectToAction("Index")); } ViewBag.CategoryID = new SelectList(db.ProductCategories, "CategoryID", "Name", product.CategoryID); return(View(product)); }
public ActionResult Create([Bind(Include = "CategoryID,ParentCategoryID,Name,rowguid,ModifiedDate")] Category category) { if (ModelState.IsValid) { db.ProductCategories.Add(category); db.SaveChanges(); return(RedirectToAction("Index")); } ViewBag.ParentCategoryID = new SelectList(db.ProductCategories, "CategoryID", "Name", category.ParentCategoryID); return(View(category)); }
// The id parameter name should match the DataKeyNames value set on the control public void DetProduit_UpdateItem([QueryString] int ProductID) { AppPrincipale.Models.Product item = null; // Load the item here, e.g. item = MyDataLayer.Find(id); item = db.Products.Find(ProductID); if (item == null) { // The item wasn't found ModelState.AddModelError("", String.Format("Item with id {0} was not found", ProductID)); return; } TryUpdateModel(item); if (ModelState.IsValid) { db.SaveChanges(); } }