0
我是MVC中的新手。我正在做一個程序,用於編輯mongodb中的現有記錄。 我的程序沒有更新記錄。我的程序沒有更新mongo db
這是編輯方法:
[HttpPost]
public async Task<ActionResult> Edit(BioCardModel model)
{
await _bioCardServices.UpdateBioCard(model.cardId ,model);
return RedirectToAction("Index");
}
這是在蒙戈DB
public async Task UpdateBioCard(Guid value, [FromBody]BioCardModel card)
{
var db = ConnectToMongo();
var collection = db.GetCollection<BioCardModel>(_collection);
var filter = Builders<BioCardModel>.Filter.Eq("cardId", value);
var update = Builders<BioCardModel>.Update
.Set(b => b.name, card.name)
.Set(b => b.firstName, card.firstName)
.Set(b => b.lastName, card.lastName)
.Set(b => b.title, card.title)
.Set(b => b.lifeSpan, card.lifeSpan)
.Set(b => b.bio, card.bio)
.Set(b => b.bio, card.anecdote)
.Set(b => b.imageFront, card.imageFront)
.Set(b => b.imageBack, card.imageBack);
await collection.UpdateOneAsync(filter, update);
}
我的觀點是一個簡單的表格,填充了一個創紀錄的數據更新記錄的方法。