使用MVC創造型球員的數據庫條目:爲什麼使用SubmitChanges時數據不存儲?
[HttpPost]
public ActionResult Create(FormCollection fc, Player player)
{
players.Players.InsertOnSubmit(player);
players.SubmitChanges();
Errors errors;
if (!IsValid(player, out errors))
{
ViewBag.Errors = errors;
return RedirectToAction("Edit", player);
}
return Redirect("/Home/Players");
}
[HttpPost]
public ActionResult Edit(FormCollection fc, Player player)
{
players.SubmitChanges();
return Redirect("/Home/Players");
}
我的問題是players.SubmitChanges()
的編輯方法不會更改數據庫中的任何東西。在創作中使用InsertObSubmit
。我可以用另一種方式來做嗎?
'player'沒有連接到數據庫。此外,這與MVC無關,但與Linq-to-SQL或Entity Framework相關。 :) – bzlm
我該如何以及在哪裏將播放器附加到數據庫?因爲Player具有global :: System.Data.Linq.Mapping.TableAttribute(Name)屬性集,所以我會假設它知道它屬於哪裏。 –