我剛開始使用MongoDB,我有問題。 雖然我嘗試通過對象到控制器,containts ID(的ObjectId),這個ID是空爲什麼ObjectId在將模型傳遞給控制器時爲空?
我的視圖代碼:
@using (Html.BeginForm()) {
<fieldset>
<legend>Product</legend>
@Html.HiddenFor(model => model.Id)
@Html.EditorFor(model => model.Name)
@Html.EditorFor(model => model.Price)
<input type="submit" value="Save" />
</fieldset>
}
操作:
[HttpPost]
public ActionResult Edit(Product product)
{
_db.Update(product);
return RedirectToAction("Index");
}
行動開始吧,我的意思,產品中的所有屬性都是正確的,但是Id(這是mongo的ObjectId)只是空的(創建日期是1970年,其餘屬性只是零)
我不知道該怎麼辦... 請幫忙。
你能顯示你的索引行動嗎? –
...和路線映射。 –
@KirillBestemyanov,但索引很好。 我在斷點上看到Id是空的。 索引操作只是'返回View()'(不,沒有產品列表,列表在其他地方,但它真的沒關係)。 –