为什么在编辑操作中修改MVC中的db时出现错误 [英] Why it showing error in modifying db in MVC in edit action

查看:83
本文介绍了为什么在编辑操作中修改MVC中的db时出现错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的项目中有一个问题,当我将数据修改为db时,它显示错误

I have a confution in my project that when I am modifying the data to db it shows the error that "

Store update, insert, or delete statement affected an unexpected number of rows (0). Entities may have been modified or deleted since entities were loaded. See http://go.microsoft.com/fwlink/?LinkId=472540 for information on understanding and handling optimistic concurrency exceptions."



我在编辑动作方法的HttpPost中得到了我需要的值,只有在将它保存到数据库时才会出现错误

控制器


I am getting the value which I needed in the HttpPost of edit action method, the error arise only when saving it to the db
controller

[HttpPost]
        [ValidateAntiForgeryToken]
        public async Task<ActionResult> Edit( StudentDetail studentDetail )
        {
            if (ModelState.IsValid)
            {
                studentDetail .CashInHand -= studentDetail .CashReceived;
                studentDetail .Amount += studentDetail .CashReceived;
                studentDetail .Date = DateTime.Now;
                studentDetail .CashReceived= null;

                db.Entry(studentDetail ).State = EntityState.Modified;
                await db.SaveChangesAsync();
                return RedirectToAction("Index");
            }
            return View(studentDetail );
        }





我在studentDetail中获取详细信息。然后为什么这个错误显示???有谁可以帮我找到解决方案?



我尝试了什么:



我搜索了我的错误,但我不明白为什么会发生这种情况任何人都可以帮我找到解决方案吗?



I am getting details in studentDetail. Then Why is that the error showing ???can anyone please help me to find the solution ??

What I have tried:

I have search the my error but i didn't understand why is that happening Can anyone please help me to find the solution ??

推荐答案

请参阅此链接,您可能会有任何想法。

asp.net - 实体框架:存储更新,插入或删除语句影响了意外的行数(0)。 - 堆栈溢出 [ ^ ]
Refer this link you may get any idea.
asp.net - Entity Framework: "Store update, insert, or delete statement affected an unexpected number of rows (0)." - Stack Overflow[^]


这篇关于为什么在编辑操作中修改MVC中的db时出现错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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