我有2个表,关系一(表A)到很多(表B)
我已经开始使用旧数据进行更新,删除和创建了 我的问题是当我向表A添加新数据并使用参考表A向表B添加新数据时 然后网格是空白的,我使用了firebug,但我不知道如何解决它
控制器
[AcceptVerbs(HttpVerbs.Post)]
public ActionResult Update([DataSourceRequest] DataSourceRequest request, ReRoom room)
{
if (room != null && ModelState.IsValid) { var target = RoomRepository.One(p => p.PKiRoomID == room.PKiRoomID); if (target != null)
{
target.SDescription = room.SDescription;
target.SRoomName = room.SRoomName; target.BStatus = room.BStatus;
target.IRoomType = room.IRoomType; RoomRepository.Update(target);
}
}
return Json(ModelState.ToDataSourceResult());
}
存储库
public static void Update(ReRoom room)
{
ReRoom target = One(p => p.PKiRoomID == room.PKiRoomID);
if (target != null)
{
target.SDescription = room.SDescription;
target.SRoomName = room.SRoomName;
target.BStatus = room.BStatus;
target.IRoomType = room.IRoomType;
}
reModel rm = new reModel();
var i = rm.ReRooms.Where(p => p.PKiRoomID == room.PKiRoomID).FirstOrDefault();
if (i != null)
{
i.SDescription = room.SDescription;
i.SRoomName = room.SRoomName;
i.BStatus = room.BStatus;
i.IRoomType = room.IRoomType;
}
rm.SaveChanges();
}
索引:
columns.ForeignKey(p => p.IRoomType, (System.Collections.IEnumerable)ViewData["Types"], "ID", "Name");
ViewData : private void populateRoomtypes() { ViewData["Types"] = new reModel().ReRoomTypes .Select(t => new { ID = t.PKiRoomTypeID, Name = t.SRoomTypeName });
}