我需要獲取特定字段「Quantity」的HttpPost Edit方法中的數據庫值,以便我可以對其進行一些操作並更新其值。我使用實體框架6.如何獲取[HttpPost]編輯方法中特定字段的數據庫值?
[HttpPost]
[ValidateAntiForgeryToken]
public async Task<ActionResult> EditGoogles([Bind(Include = "ProductID,Name,Code,Quantity,etc)] SalesDetail salesdetail)
{
if (ModelState.IsValid)
{
var oldValue = db.Entry(salesdetail).GetDatabaseValues();
//here i want to get the Quantity from database
int QtyBefore = ???;
db.Entry(salesdetail).State = EntityState.Modified;
salesdetail.Quantity = //do some operaion with QtyBefore Here and update
await db.SaveChangesAsync();
return Json(new { success = true });
}
return PartialView("_EditSales", salesdetail);
}
最新問題 –