Apress Pro Asp.net MVC Framework 3 - SportsStore Edit Product not working?

后端 未结 7 2047
慢半拍i
慢半拍i 2021-02-13 23:33

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

7条回答
  •  孤独总比滥情好
    2021-02-13 23:50

    I can't yet post comments but I would like to add to MVC Newbie's comment by showing what your final method should read:

    public void SaveProduct(Product product) {
        if (product.ProductID == 0) {
            context.Products.Add(product);
        } else {
            context.Entry(product).State = EntityState.Modified;
        }
        int numSaved = context.SaveChanges();
    }
    

    Also don't forget to add the extra using statement (again as mentioned by MVC Newbie):

    //using system.data;
    

提交回复
热议问题