我正在尝试获取模型主键的值
然而我得到0
我的代码是
if (ModelState.IsValid)
{
context.Upload_Transaction.Add(upload_Transaction);
await context.SaveChangesAsync();
id = Upload_Transaction.Upload_TransactionID;
ViewData["id"] = id; // For some reason this returns 0
}
答案 0 :(得分:0)
如果您更改了代码;
id = Upload_Transaction.Upload_TransactionID;
到
id = upload_Transaction.Upload_TransactionID;
那应该解决这个问题。您正在尝试从错误的对象中读取新ID。