-1
私は単純なMVC 5アプリケーションを持っています。コントローラでは、db.SaveChanges()
が呼び出される前にデータベースから現在のデータにアクセスする方法を知りたいと思います。私はそれが新しい値を取得しているproduct.title
をすれば、私は保存する前に古い値にアクセスしたい、ASP.NET MVCで更新時に古いエンティティ値を取得する方法
// GET:
public ActionResult Edit(int id)
{
Product product = db.Products.Find(id);
return View(product);
}
// POST:
[HttpPost]
public ActionResult Edit([Bind(Include = "id,title,content,price)] Product product)
{
/* How to access old value from database here? */
db.Entry(product).State = EntityState.Modified;
db.SaveChanges();
}
:私は、次のコードを持っています。
私はこのリンクで承認された回答を試みました:How to access old entity value in ASP.NET Entity Frameworkしかし、それは私のためには機能しませんでした。