如何编辑&将数据保存在MVC中的数据库中 [英] How to edit & save data in database in MVC
本文介绍了如何编辑&将数据保存在MVC中的数据库中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
尊敬的先生,
我是MVC新手,
我通过传递id来更新客户数据,但是没有更新它。
如何更新数据?
我做错了吗?如果有其他方法可以告诉我。
谢谢。
我的尝试:
Dear sir(s),
I am new in MVC,
I am updating customer data by passing only id, but not updating it.
How to update data?
Am i doing wrong?.Please suggest me if another way is available.
Thanks.
What I have tried:
[HttpPost, ActionName("Edit")]
[ValidateAntiForgeryToken]
public ActionResult Edit(int id)
{
Customers customers = db.Customers.Find(id);
if (TryUpdateModel(customers)) /* <- here debug point doesnt go inside*/
{
customers.Active = false;
db.SaveChanges();
}
}
推荐答案
您需要传递需要保存的变量
例如
public ActionResult Edit(INVENTORY iis_inventory,string TYPE_CODE,string bc,bool as)
{
iis_inventory.invServiceType = TYPE_CODE;
....
...
db.SaveChanges();
}
You need to pass the variables that you need to save
for example
public ActionResult Edit(INVENTORY iis_inventory, string TYPE_CODE, string bc, bool as)
{
iis_inventory.invServiceType = TYPE_CODE;
....
...
db.SaveChanges();
}
这篇关于如何编辑&将数据保存在MVC中的数据库中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文