我在编辑表格中的列时遇到问题,即使我可以很容易地添加和删除它们。我以前做过这种事情并且没有任何问题,所以我很困惑为什么它现在会发生。
我可以单击球员姓名并获取他的详细信息,但是当我在视图中编辑球员详细信息并单击保存时,它说序列不包含任何元素。
有人可以帮我解决这个问题,因为它让我发疯,非常感谢,因为它很可能是一个简单的解决方案。
这是我的代码:
存储库:
public Players PlayersDetails(String Name)
{
var players = (from p in _entities.Players
where p.FullName == Name
select p).First();
return players;
}
public void playersEdit(Players playersToEdit)
{
var originalPlayer = PlayersDetails(playersToEdit.FullName);
_entities.ApplyPropertyChanges(originalPlayer.EntityKey.EntitySetName, playersToEdit);
_entities.SaveChanges();
}
存储库:
public interface IHuddRLRepository
{
//Player List
IEnumerable<Players> PlayersList();
Players PlayersDetails(String Name);
void playersCreate(Players playersToCreate);
void playersEdit(Players playersToEdit);
void playersDelete(Players playersToDelete);
}
控制器:
public ActionResult Edit(String FullName)
{
Players players = _entities.PlayerDetails(FullName);
return View(players);
}
[ValidateInput(false)]
[AcceptVerbs(HttpVerbs.Post)]
public ActionResult Edit(Players playersToEdit)
{
if (!ModelState.IsValid)
{
return View();
}
else
{
_entities.playersEdit(playersToEdit);
return RedirectToAction("Index", "Players");
}
}