G’day All, has anyone purchased the ALPHA of Apress Pro Asp.net MVC Framework 3 and created the SportsStore? I can’t for the life of me edit products and have the DB update suc
try this
public ActionResult Edit(Product product)
{
if (ModelState.IsValid)
{
Product p = repository.Products.FirstOrDefault(x => x.ProductID == product.ProductID);
if (p != null)
{
p.ProductID = product.ProductID;
p.Price = product.Price;
p.Category = product.Category;
p.Description = product.Description;
p.Name = product.Name;
}
else
p = product;
repository.SaveProduct(p);
TempData["message"] = string.Format("{0} has been saved", product.Name);
return RedirectToAction("Index");
}
else
{
return View(product);
}
}
im beginner with mvc 3, but i think the model reference (product parameter) is a Product object that is not bind to EF Context