一个preSS临Asp.net MVC框架3 - SportsStore编辑产品不能正常工作? [英] Apress Pro Asp.net MVC Framework 3 - SportsStore Edit Product not working?

查看:138
本文介绍了一个preSS临Asp.net MVC框架3 - SportsStore编辑产品不能正常工作?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

所有儿真好,有没有人购买了一个preSS临Asp.net MVC框架3的ALPHA,创造了SportsStore?我不能为我的生活编辑产品,并成功有DB更新?不显示错误,单元测试所有的功能,但没有成功的'编辑',即我改变一些细节,然后点击保存,它会报告成功 - 那么我检查结果,并没有什么事了?通过SportsStore工作时没有其他人发现吗?任何意见将大大AP preciated。

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 successfully? No errors are displayed and unit tests all function, but no successful ‘edit’ i.e. I change some details, click save, it reports successful – I then check the results, and nothing has happened? Did anyone else find this when working through the SportsStore? Any advice will be greatly appreciated.

干杯。

推荐答案

需要保存之前要更新的EF对象的状态。

The state of the EF object needs to be updated before saving.

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


            int result = context.SaveChanges();

        }

这篇关于一个preSS临Asp.net MVC框架3 - SportsStore编辑产品不能正常工作?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆